Script: Search for Photos by the Dimensions in Pixel Size

by: 
Last modified: May 29, 2017 4:55 AM
2 4725 Last modified May 29, 2017 4:55 AM

(* How to use this script:


This script will split the selection into two albums -

- one album with pictures with the largest dimension smaller or equal than the given pixel size

- one album with pictures with the largest dimension larger than the given pixel size



Open this script in Script Editor. Launch Photos.

Select the Photos you want to distribute between the albums.


When all all photo are selected, press the "Run" button in Script Editor.


Author: léonie

*)


set defaultSizeThreshold to 256 -- change this to the pixel size threshold you want for a photo to be counted as small


set dialogResult to display dialog ¬

"Enter the pixel size threshold for small photos: " buttons {"Cancel", "OK"} ¬


default answer (defaultSizeThreshold as text)

set AspectRatioThreshold to (text returned of dialogResult) as integer



set smallAlbumName to "smallerThan" & AspectRatioThreshold-- the album to collect the small photos


set largeAlbumName to "largerThan" & AspectRatioThreshold-- the album to collect the larger photosphotos


tell application "Photos"


activate


-- Ensure that the albums do exist


try

if not (exists container smallAlbumName) then


makenewalbumnamedsmallAlbumName

end if

set theSmallAlbum to containersmallAlbumName


if not (exists container largeAlbumName) then


makenewalbumnamedlargeAlbumName

end if

set theLargeAlbum to containerlargeAlbumName


if not (exists container "SkippedPhotos") then

make new album named "SkippedPhotos"

end if

set theSkippedAlbum to container "SkippedPhotos"



on error errTexttwonumbererrNumtwo

display dialog "Cannot open albums: " & errNumtwo & return & errTexttwo

end try



-- process the selected photos from the All Photos album

try

set imageSel to (get selection)

on error errTexttwonumbererrNumtwo

display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo

end try


set smallPhotos to {} -- the list of small photos

set largePhotos to {} -- the list of larger photos

set skippedPhotos to {} -- the list of skipped photos




-- check, if the album or the selected photos do contain images


if imageSel is {} then

error "Please select some images."

else

repeat with im in imageSel

try


tell im--get the pixel size

set h to its height

set w to its width

end tell

on error errText number errNum

display dialog "Error: " & errNum & return & errText & "Trying again"

try

delay 2

tell im

set h to its height

set w to its width

end tell

on error errTexttwonumbererrNumtwo

display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo

end try


end try

set noDimensions to (w is missing value) or (h is missing value)

if noDimensions then

set skippedPhotos to {im} & skippedPhotos

else

if (wh) then

set largestDimension to h

else

set largestDimension to w


end if

if (largestDimensionAspectRatioThreshold) then

set smallPhotos to {im} & smallPhotos

else

set largePhotos to {im} & largePhotos


end if

end if


end repeat



addsmallPhotostotheSmallAlbum


addlargePhotostotheLargeAlbum


addskippedPhotostotheSkippedAlbum


return "small photos: " & (length of smallPhotos) & ", larger photos : " & (length of largePhotos) & ", skipped: " & (length of skippedPhotos)


end if


end tell


This user tip was generated from the following discussion: Ever since my iPhotos was transferred to Photos I have many low resolution images. What are their function and how do I delete them?

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