Script: Split a set of selected photos by the altitude EXIF tag into two albums

by: 
Last modified: Jun 1, 2017 12:13 PM
1 3206 Last modified Jun 1, 2017 12:13 PM

This script will take the selected albums and create two albums, one with all photos taken at a lower altitude than a given threshold, and one with photos taken at a higher altitude.

An additional album "Skipped" will contain items without an altitude tag.


User uploaded file

-- copy from here to the script editor

(*

This script will take a set of photos selected in Photos and then search for photos taken at an altitude higher than a given altitude threshold


How to use this script:


Select some photos to be searched for photos taken at a high altitude


This script will split the selection and add the photos to two albums:

- HighAltitudeAlbum: an album with photos taken at a higher altitude than the threshold

- LowAltitudeAlbum: an album with photos taken at a lower altitude than the threshold


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

*)


setdefaultAltitudeThreshold to 1000 -- (1000 m) -- high altitude starts at 1000 m

setdialogResulttodisplay dialog ¬

"Enter the minimum altitude in meters : " buttons {"Cancel", "OK"} ¬


default answer (defaultAltitudeThresholdastext)

setAltitudeThreshold to ((text returnedofdialogResult) as real)


--return AltitudeThreshold


tell application "Photos"


activate

try

set imageSel to (get selection)

on error errTexttwonumbererrNumtwo

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

end try

end tell





onsplitPhotosByAltitude(minAltitude, selectedPhotos)


-- the altitude, real number


-- altiAlbumName: the name of the album to collect the photos, string


-- selectedPhotos: a list of media items


-- DistanceThreshold: the threshold for the distance from the circle, in km, real number

set lowAltiAlbumName to "Altitude lower than " & minAltitude & " m"

set highAltiAlbumName to "Altitude higher than " & minAltitude & " m"


set lowAltis to {} -- the list of altitude photos

set highAltis to {} -- the list of altitude photos


set skipped to {} -- not yet used, just for debugging

if selectedPhotos is {} then

error "Please select some images."

end if


tell application "Photos"


activate


-- Ensure that the albums do exist


try

if not (exists container highAltiAlbumName) then


makenewalbumnamedhighAltiAlbumName

end if

set theHighAltiAlbumtocontainerhighAltiAlbumName


if not (exists container lowAltiAlbumName) then


makenewalbumnamedlowAltiAlbumName

end if

set theLowAltiAlbumtocontainerlowAltiAlbumName


if not (exists container "SkippedAltitudes") then

make new album named "SkippedAltitudes"

end if

set theSkippedAltiAlbum to container "SkippedAltitudes"



on error errTexttwonumbererrNumtwo


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

end try


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


if selectedPhotos is {} then

error "Please select some images."

else

repeat with im in selectedPhotos

try


tell im--get the altitude

set alti to get its altitude--retrieve the altitude

end tell

on error errText number errNum

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

try

delay 2

tell im

set alti to get its altitude --retrieve the altitude

end tell

on error errTexttwonumbererrNumtwo

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

end try


end try

set noAltitude to (alti is missing value)


if noAltitude then

set skipped to {im} & skipped -- for testing

else

set alti to alti as number


if (alti < minAltitude) then

set lowAltis to {im} & lowAltis

else

set highAltis to {im} & highAltis


end if


end if


end repeat



addlowAltistotheLowAltiAlbum


addhighAltistotheHighAltiAlbum


addskippedtotheSkippedAltiAlbum

return "low altitude photos: " & (length of lowAltis) & ", high altitude photos: " & (length of highAltis) & ", skipped photos: " & (length of skipped)

end if


end tell


endsplitPhotosByAltitude


-- call the script for the circles you want


setaltisFoundtosplitPhotosByAltitude(AltitudeThreshold, imageSel)

Comments

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