Access the most recent folder of pictures on a smartphone

Post your working scripts, libraries and tools
lkb3
Posts: 57
Joined: 13 Mar 2014, 16:17

Access the most recent folder of pictures on a smartphone

17 Apr 2015, 15:13

This script will query a smartphone's file system for the folders which contain pictures, find the most recent folder, and launch a windows explorer window. This is useful when directly navigating the picture folders of an iPhone, where the folder names are something like 842HIQIZ, and the time stamp is not helpful.
It has been tested on Windows 7 64bit Professional with an iPhone. it may work with other devices, but I don't know.

Thanks to Lexikos for the ComObj functions that form the core of the script.

Code: Select all

/*
lkb3 17Apr2015
This script uses a ComObj call to access a smartphone's file system, and open a Windows explorer window open to the folder on the phone which contains the most recent photos.

This version was designed to be used with any phone, not just mine, but it does rely on the Internal Storage\DCIM folder, so it might only work with iPhones
Also will only work if
1) the phone identifies as "portable Device"
2) there's only one "portable device" connected to the computer

tested on Win 7 64bit Professional 

based heavily on code from code from lexikos
*/

; get handle to the device
phone := GetDeviceFolder()
camera := phone.ParseName("Internal storage\DCIM\").GetFolder()

; get the device's name to be used in constructing the folder path
name := GetDeviceName()

if (camera.Items.Count() < 1)
	{
	msgbox No phone or camera found. 
	}
else
	{
	; get the most recent folder
	lastItem := camera.Items.Item(camera.Items.Count()-1).Name
	
	;construct the path to the most recent folder
	fullName =computer\
	fullname .=name
	fullname .="\Internal Storage\DCIM\"
	fullName .= lastItem
	fullName .= "\"
	
	; open Windows explorer
	Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d} 
	WinWait Computer
	WinActivate Computer
	WinMaximize, A
	CoordMode, Mouse, Window
	Click, 1425, 45, 1  ; click in the address bar at the top of the window
	SendInput %fullName%
	SendInput {Enter}
	}



GetDeviceFolder() {
    shell := ComObjCreate("Shell.Application")
    computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
    for item in computer.Items
		if (item.Type =="Portable Device")
			return item.GetFolder()
   }
   
   GetDeviceName() {
       shell := ComObjCreate("Shell.Application")
       computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
       for item in computer.Items
   		if (item.Type =="Portable Device")
   			return item.Name
   }
lexikos
Posts: 6731
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Access the most recent folder of pictures on a smartphon

18 Apr 2015, 05:41

Adding || item.Type == "Digital Camera" might allow it to work on more phones and cameras.

My Nexus 4 identifies as that type, but since it seems to put all photos into one folder, I suppose it's a moot point.

You can simplify your script significantly by opening the folder via the FolderItem object. This worked for me:

Code: Select all

lastItem := camera.Items.Item(camera.Items.Count()-1)
if lastItem.IsFolder
    lastItem.InvokeVerb()  ; Invoke the default verb for this item (open).
You can also Run % lastItem.Path, though Path returns something that isn't human-readable.
lkb3
Posts: 57
Joined: 13 Mar 2014, 16:17

Re: Access the most recent folder of pictures on a smartphon

24 Apr 2015, 14:02

Wow. That's great. Thanks, lexikos. Much simpler & faster now:

Code: Select all

/*
lkb3 24Apr2015
This script uses a ComObj call to access a smartphone's file system, and open a Windows explorer window open to the folder on the phone which contains the most recent photos.

This version was designed to be used with any phone, not just mine, but it does rely on the Internal Storage\DCIM folder, so it might only work with iPhones
Also will only work if
1) the phone identifies as "portable Device"
2) there's only one "portable device" connected to the computer

tested on Win 7 64bit Professional 

based heavily on code from code from lexikos
*/

; get handle to the device
phone := GetDeviceFolder()
camera := phone.ParseName("Internal storage\DCIM\").GetFolder()

; get the device's name to be used in constructing the folder path
name := GetDeviceName()

if (camera.Items.Count() < 1)
	{
	msgbox No phone or camera found. 
	}
else
	{
	; get the most recent folder
	lastItem := camera.Items.Item(camera.Items.Count()-1)
	; open it
	if lastItem.IsFolder
		lastItem.InvokeVerb()

	}



GetDeviceFolder() {
    shell := ComObjCreate("Shell.Application")
    computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
    for item in computer.Items
		if (item.Type =="Portable Device")
			return item.GetFolder()
   }
   
   GetDeviceName() {
       shell := ComObjCreate("Shell.Application")
       computer := shell.Namespace("::{20d04fe0-3aea-1069-a2d8-08002b30309d}")
       for item in computer.Items
   		if (item.Type =="Portable Device")
   			return item.Name
   }
lexikos
Posts: 6731
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Access the most recent folder of pictures on a smartphon

24 Apr 2015, 18:14

name := GetDeviceName() and the function itself are now unused, but still present in your script.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 38 guests