AppleScript and Photos in Catalina

In Mojave I used this simple script to add photos to albums, based on keywords of the same name:


tell application "Photos"

activate


set albumNameList to name of albums -- lists all album names

set theSel to selection


set keywordsList to {}


repeat with thePic in theSel -- loops through selected pictures


set keywordsList to keywords of thePic -- list of keywords in selected picture

set theCount to 1


repeat with theAlbumName in albumNameList -- determines matching keyword and album, then adds

if theAlbumName is in keywordsList then

set theAlbum to item theCount in albumNameList

try

add thePic as list to album theAlbum -- note that pictures must be added as list

end try

end if

set theCount to theCount + 1

end repeat


end repeat


end tell


but in Catalina I'm having problems getting around media item ids. Does anyone have any ideas about this?


Many thanks!

Replies

My problem is that thePic in the above script is returned in this form:


media item id "4650C218-7E28-497E-BD25-39431ACD9CFC/L0/001" of album id "959DB188-8B5D-4D6E-ADF5-6B44A0AB8465/L0/040" of application "Photos"


which means that script effectively asks for this:

keywords of {media item id "4650C218-7E28-497E-BD25-39431ACD9CFC/L0/001" of album id "959DB188-8B5D-4D6E-ADF5-6B44A0AB8465/L0/040" of application "Photos"}


which gives the result:


error "Can’t get keywords of {media item id \"4650C218-7E28-497E-BD25-39431ACD9CFC/L0/001\" of album id \"959DB188-8B5D-4D6E-ADF5-6B44A0AB8465/L0/040\" of application \"Photos\"}." number -1728 from «class IPkw» ofclass IPmi» id "4650C218-7E28-497E-BD25-39431ACD9CFC/L0/001" of «class IPal» id "959DB188-8B5D-4D6E-ADF5-6B44A0AB8465/L0/040"}


My problem is that trying to get the keywords from the actual media item id does work, as in this:


keywords of {media item id "2026B920-91EE-4626-B426-7369B99FADBE/L0/001"}


Does anyone know how I can extract the media item id element alone, without the album id component?
It looks as though it should be easy, but I can't see a solution. Or is there a bigger problem with scripting Photos in Catalina?
Many thanks!

Hi, set keywordsList to keywords of item 1 of thePic .... however, your script may not work as expected, as the Photos app database has been completely rewritten and unfortunately, with AppleScript, currently only top-level albums are found. greetings

Thanks for replying and apologies for my slow answer. Yes, only top level albums work. Most annoying...

Hi Raytw,
Did you ever find out the answer to this problem you are encountering. I am trying to figure out how to identify the albums that photos are hidden in and can't get past first base. I was trying to use the script originally developed by Jacques Rioux and updated by léonie and have hit the same errors you ave found.
Thanks