Scroll through each photo in Photos

I want to clear my photo library and especially move all my iPhone screenshots to a new album so that I can view them easily and delete what I want.

Now for this, I first wanted to create a smart album in Photos, but it seems that photos cannot filter image sizes, so I ran AppleScript editor :).

I created the following script that works on the "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 goes through the album named Test Album

and compares the height and width to the dimensions of the iPhone 5S. When they match, he adds the photo to the library Screenshots

. No problems.

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 if it passed the first element ( 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 due to the number of photos in this library (27.000).

Is there a way to list through such a set?

EDIT: Changing the line set

containing the best query has the same effect, resulting in AppleEvent handler failed

an error number -10000

.

set all_images to every media item whose width = target_width and height = target_height

+3


source to share


2 answers


The -10000 error is caused by a bug in Photo 1.0. I filed this with Apple as radar 20626449 (on OpenRadar at http://openradar.appspot.com/radar?id=6090497735000064 ). The error is intermittent, but the more photos there are in the library, the more likely it will be executed in any scripting command.



There is no completely reliable way of reporting the error, but one thing that seems to help is if you select All Photos in Photos before running the script. Unfortunately Photos AppleScript doesn't have the ability to select an album, so you need to do it manually before running the script.

+3


source


Not sure if you have a problem with shell sending in terminal or if you can make it work with iPhoto, but if that's ok you can start looking for all files in your HOME directory and below that PNG

and that match yours size ...

#!/bin/bash
isIphone() {
   # Get width using sips, don't bother getting height if not 640 wide
   w=$(sips -g pixelWidth  "$1" | awk 'END{print $2}')
   [ "$w" != "640" ] && return
   # Get height using sips, just return if not iPhone size
   h=$(sips -g pixelHeight "$1" | awk 'END{print $2}')
   [ $h != "1136" ] && return
   # Output image size and name
   echo $w,$h, $1
}

# Go through all PNG files in HOME directory listing iPhone-sized ones
find ~ -iname "*.png" -type f -print0 | while read -d $'\0' -r file ; do isIphone "$file"; done

      



Output

640,1136, ./iPhone/2013 09 iPhone/IMG_0269.PNG
640,1136, ./iPhone/2013 09 iPhone/IMG_0363.PNG
640,1136, ./iPhone/2013 09 iPhone/IMG_0376.PNG

      

0


source







All Articles