AppleScript add photos to album

This should be easy, and I probably have not had enough coffee.


I am trying to cycle through every selected photo and add it to an album based on it's name. I can test if the album exists successfully and even add it if it doesn't. Where I keep failing is the command to add the image to the album.


Assuming theImage is the image reference in my repeat and theAlbumName is name of the Album I am trying to add to:


add theImage to album theAlbumName


I assume I need to get the reference to the actual album, not just it's name, but trying


set theAlbum to album with name theAlbumName

add theImage to album theAlbum


also fails. What obvious thing am I missing?

Mac OS X (10.7.5)

Posted on Mar 25, 2018 9:04 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 25, 2018 9:44 AM

It is a type conflict. You can add a list of images to an album, but not a single image. To add an image to an album, you have first to create a list with the image in it.

Try


set imagelist to {theImage} -- make a list with one image

tell application "Photos"

add imagelist to thealbum

end tell



For example; I used this to add photos to an album in this script: : Script: How to find videos and photos in your Photos Library larger or smaller than a given file size

Similar questions

2 replies
Question marked as Top-ranking reply

Mar 25, 2018 9:44 AM in response to Gary Learned

It is a type conflict. You can add a list of images to an album, but not a single image. To add an image to an album, you have first to create a list with the image in it.

Try


set imagelist to {theImage} -- make a list with one image

tell application "Photos"

add imagelist to thealbum

end tell



For example; I used this to add photos to an album in this script: : Script: How to find videos and photos in your Photos Library larger or smaller than a given file size

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.

AppleScript add photos to album

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