1 Reply
      Latest reply on Oct 12, 2019 9:02 AM by raytw
      raytw Level 1 Level 1 (0 points)

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


        tell application "Photos"



          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


          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!

        • Re: AppleScript and Photos in Catalina
          raytw Level 1 Level 1 (0 points)

          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!