Sending file to Photos.app using AppleScript

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I'm by no means an expert when it comes to AppleScript so please bear with me...

I have this script (provided by someone at macscripter.net) and if I use it using a predefined path to a file using the ScriptEditor, I can copy the file to the Photos app:
Code: Select all
set imageList to (POSIX file "/Users/dannywyatt/My Files/Inbox Global/_Awesome Argument.mp4" as alias)
importToAlbum(imageList, "Testing")
on importToAlbum(imagePathList, albumName)
   tell application "Photos"
      set albumNames to name of albums
      if albumName is in albumNames then
         import imagePathList into album albumName
      else
         make new album named albumName
         import imagePathList into album albumName
      end if
   end tell
end importToAlbum


Now when I try to use it in Hazel like this:
Code: Select all
set imageList to theFile
importToAlbum(imageList, "Test")
on importToAlbum(imagePathList, albumName)
   tell application "Photos"
      set albumNames to name of albums
      if albumName is in albumNames then
         import imagePathList into album albumName
      else
         make new album named albumName
         import imagePathList into album albumName
      end if
   end tell
end importToAlbum


It doesn't work. It highlights the "on" here: "on importToAlbum(imagePathList, albumName)" and at the bottom it says "Expected end, but found on".

Any tip on how to make this work?
Thank you
Danny Wyatt
 
Posts: 25
Joined: Wed Mar 23, 2022 7:39 am

The "on" is a handler, which you cannot use inside an embedded script. In an external script, Hazel requires its own specific handler so you would need to modify the script to take that into account. Check the manual as it documents this all.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support