Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript for Photos to set all my albums to Sort By Title/Name

I've already ran the script that copies the photo titles to names (worked great!)


Now I would like to set all my albums to be sorted by Title/Name. I can't seem to figure out how to batch it and currently have to right-click every album (2 decades/50k photos) and manually set it to Sort > By Name


My folder structure in Photos are:

My Albums > Year (folder) > Album name > (photos)

and also

My Albums > Year (folder) > Folder > Album name > (photos)


Can someone please point me in the right direction? Thanks!!


iMac with Retina 5K display, macOS 10.15

Posted on Jul 26, 2020 3:16 PM

Reply
Question marked as Best reply

Posted on Jul 27, 2020 3:28 AM

On Catalina it is really tedious. In the older version of Photos you could simply ask the application for a list of all albums, but on Catalina we have to traverse all folders recursively:

The old method (Photos 1 to 4) to return list of all album names:

tell application "Photos"
	set allalbums to the albums
	set theseNames to name of albums
end tell


The new method on Catalina (slow as molasses)

set allfolders to {}

tell application "Photos"
	
	set allalbums to the albums --  collect all albums, get the top level albums
	
	set level to 0 -- nesting level of folders
	
	set nextlevelFolders to the folders -- get the top level folders
	set currentLevelFolders to {}
	
	repeat while (nextlevelFolders is not {})
		set currentLevelFolders to nextlevelFolders
		set nextlevelFolders to {}
		repeat with fi in currentLevelFolders
			tell fi
				set ffolders to its folders
				set falbums to its albums
				set nextlevelFolders to ffolders & nextlevelFolders
				set allalbums to falbums & allalbums
			end tell
		end repeat
		set allfolders to currentLevelFolders & allfolders
		set level to level + 1
	end repeat
	
end tell


You will find many scripts on this index page for user tips: https://discussions.apple.com/docs/DOC-250000226


Similar questions

6 replies
Question marked as Best reply

Jul 27, 2020 3:28 AM in response to jessy65

On Catalina it is really tedious. In the older version of Photos you could simply ask the application for a list of all albums, but on Catalina we have to traverse all folders recursively:

The old method (Photos 1 to 4) to return list of all album names:

tell application "Photos"
	set allalbums to the albums
	set theseNames to name of albums
end tell


The new method on Catalina (slow as molasses)

set allfolders to {}

tell application "Photos"
	
	set allalbums to the albums --  collect all albums, get the top level albums
	
	set level to 0 -- nesting level of folders
	
	set nextlevelFolders to the folders -- get the top level folders
	set currentLevelFolders to {}
	
	repeat while (nextlevelFolders is not {})
		set currentLevelFolders to nextlevelFolders
		set nextlevelFolders to {}
		repeat with fi in currentLevelFolders
			tell fi
				set ffolders to its folders
				set falbums to its albums
				set nextlevelFolders to ffolders & nextlevelFolders
				set allalbums to falbums & allalbums
			end tell
		end repeat
		set allfolders to currentLevelFolders & allfolders
		set level to level + 1
	end repeat
	
end tell


You will find many scripts on this index page for user tips: https://discussions.apple.com/docs/DOC-250000226


Jul 26, 2020 3:35 PM in response to jessy65

The dictionary for Photos in Apple Script does not have a single command to set the sort order for albums.

You would have to use GUI Scripting - write a script that is pushing the buttons in the Photos interface.


I have given up on writing these kind of scripts, because they are usually not very robust and will break after each system upgrade.

You can find some information on GUI scripting in this documentation: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/AutomatetheUserInterface.html

Jul 30, 2020 3:45 PM in response to léonie

Sorry, I wasn't able to follow any of the syntax of your traverse code as it was REALLY complex! But, when you mentioned GUI Scripting, a light bulb went off and I remembered how keyboard 'App Shortcuts' made my life easier.


To reduce redundancy, I already had to take the time to manually, one by one, change the structure from:

My Albums > Year (folder) > Folder > Album name > (photos)

My Albums > Year (folder) > Album name > (photos)


So once all the albums where in the Year folder, all I needed was go down the line and simply select the Album and do a keyboard shortcut to sort it. Doesn't sound like much, but that simple trick saved me a TON of time and a lot of frustration from having to right-click and navigate submenus. And, also, in Photos 5.0, it automatically selects the first photo as they Key Photo which is perfect!

AppleScript for Photos to set all my albums to Sort By Title/Name

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.