I want to clean up my Photos library and especially move all my iPhone screenshots to a new album, that way I can easily look through them and delete what I want.
Now for this I first wanted to make a smart album in Photos, but it seems that Photos can't filter on the dimensions of an image, so I started up the AppleScript Editor :).
I created the following script, which works on a "Test Album" I created:
tell application "Photos" set source_album_name to "Test Album" set target_album_name to "Screenshots" set target_width to 640 set target_height to 1136 if not (exists container named target_album_name) then make new album named target_album_name end if set target_album to container target_album_name set source_album to container source_album_name set imageList to {} repeat with photo in media items in source_album if width of photo = target_width and height of photo = target_height then set the end of imageList to photo end if end repeat add imageList to target_album end tell This script loops through an Album named Test Album and compares the height and width to the dimensions of an iPhone 5S. When they match, it adds the photo to the Screenshots library. No problems there.
Now I want to run this script on my entire photo collection, so I changed the line repeat with photo in media items in source_album to repeat with photo in every media item.
This generates an error once it is past the first item (Photos got an error: Can’t get item 2 of every media item. Invalid index).
After that I changed the code to:
set all_images to every media item repeat with photo in all_images but after loading for a while, the script exits with code -10000, probably because of the amount of photos in that library (27.000).
Is there some way to page through a set like this?
EDIT: Changing the set line to contain a better query has the same effect, resulting in an AppleEvent handler failed with error number -10000.
set all_images to every media item whose width = target_width and height = target_height
every media itemmight include, say audio tracks, which may not have a height/width?widthandheightproperties are integers and can never be amissing value. (Also tried it, and it crashes right at the first record, with an integer to missing value conversion error).