Using Applescript to select an album in Photos

Does anyone know how to achieve the same effect in Photos as 'tell application "iPhoto" to select album anAlbum' does in scripts for iPhoto? AppleScript Library does not list "select", and the obvious try-out does not work. Thanks in advance to anyone who can help here.

MacBook Pro 15", macOS 10.14

Posted on Jan 28, 2020 6:44 AM

Reply

Similar questions

13 replies

Jan 29, 2020 10:24 AM in response to RobertDHarding

Robert, OT asked me to drop in, but I do not know any way to select items in Photos using Apple Script. The Apple Script Dictionary for Photos is so limited, as you already found out.

In the earlier system versions we could use Automator to record our mouse clicks and turn this into a script with "Watch me do", but I cannot get it to work any longer in Catalina. perhaps recording a script in Automator will work for you in Mojave.



Jan 30, 2020 3:58 AM in response to léonie

Thank you Leonie. I had thought about using Automator, but I have hardly any experience of using it and initially couldn't get it to work at all. Encouraged by your helpful reply, I had another go and managed to record a "Quick action" in which I open Photos, select an album, then a photo in it and duplicate it. I tracked down the .workflow file, showed package contents, and opened the xml document. After all the usual xml headers there's just a big chunk of binary code. When I ran the workflow, I could see the cursor flying about but the process failed with a "-50" error. It seems to me that even if I could get this to work it would be little help as it will not be selecting an album by name or reference (apart from not being able to see any script to do that).


It seems I must find another way to achieve what I want without being able to select an album via a script. This means I cannot change the sort view option for a selection of albums in a single run. (In iPhoto I was using a repeat loop with "select <album i> then System Events to "click on ... <menu item>"). Think I've got a solution in mind but it will not have the generality I could get with iPhoto.


Thanks for your advice though. I'll focus now on using what Apple have provided in the Dictionary for Photos.

Jan 30, 2020 8:50 AM in response to léonie

Hi Léonie - yes I have got this aspect of AppleScript to work with Photos on OS 10.14. I can get lists of albums, use the 'Choose from list" command to make multiple choices, then download or update metadata from the media items. My problem is that there's no way to set the sort order of the media items via script. In iPhoto that was also the case if restricted to the Library for iPhoto, but I could use System Events script to click on items in the View menu. That part also works for Photos, but the trouble is that the View menu only operates on the currently selected album. You can't script "click on album ..." but in iPhoto you could select it. That would cause iPhoto to select & highlight that album, and then the scripted click on the View menu would set the sort order. The missing link in Photos is the "select album ..." command - hence this discussion.


Being unable to select an album via scripting also means that you cannot get the View / Sort setting except for the currently selected album. My scripts export the metadata they download into CSV format, and then it can be re-ordered using standard spreadsheet functions, editing done as required, saved in CSV format and uploaded back to iPhoto or hopefully Photos. It's currently easy in iPhoto because if the ordering is the same you can just work through photos 1,2,3,4... etc. If the ordering isn't known and may therefore differ between CSV file and album, then I'll need to use the media item id. So the problem isn't insuperable, but I'll not be able to script for a new ordering.



Jan 30, 2020 10:45 AM in response to RobertDHarding

My main macs are now running Catalina, and there even the command "set allalbums to the albums" does no longer work.

When I run the script snippet I posted above on a Mac with Mojave, it will return a count of 820 albums. Run on Catalina (for the same iCloud Photos Library") it will just count 8 albums. I can currently only access the top level albums by telling Photos to get "the albums". Scripting Photos is getting more and more difficult, for example using third-party scripting additions (https://forum.latenightsw.com/t/use-satimage-scripting-additions-on-catalina-and-mojave/1576)

Jan 30, 2020 11:32 AM in response to léonie

Thank you both so much! OK there's no easy solution, and it may be I'm on a hiding to nothing trying to port my iPhoto scripts. I should park the project for a few months and not upgrade to Catalina I think. Meanwhile, I'll explore Lightroom: that certainly has a more fully featured menu than Photos, and apparently it has a built in scripting language called Lua. Or maybe, just, if the wind is from a fair quarter, it will already have the metadata editing facilities I want...


Thanks again - everything you have said has been useful, either confirming my own suspicions or suggesting new avenues.


Jan 30, 2020 11:44 AM in response to RobertDHarding

I am currently using Power Photos as a second browser for my Photos Library.

It offers a nice column view, where I can see the metadata of the photos as a table.

Even the free trial version can sort the photos simply by the column I click. So I can sort by the filename or the size, the captions. The first launch of PowerPhotos needs a very long time, because it needs to index the library. But it is worth it. It is great to be able to have the Photos Library open in two separate windows.


Jan 30, 2020 5:57 AM in response to RobertDHarding

What you could try is to ask the user for the name of an album as a string and then search for an album with this name.


This used to work in Photos 1 to 4, but is broken in Photos 5 on Catalina. Is the system version macOS 10.14 given below your question still current?

In the early versions of Photos you can get a list of all albums like this:

tell application "Photos"
	set allalbums to the albums
	--	set theseNames to name of albums
end tell
return (the count of allalbums)-- for example

Then compare the string with the album name to the names of the albums in the list.

set foundAlbums to (albums whose name is ... )



This will still not select the album, but you can work on the album in the script - add photos to the album, play it as a slideshow, etc.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using Applescript to select an album in Photos

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