-- Inspect the images selected in macOS Photos, and if one and only one of them has a geographical location, copy that to the other images in the selection, too.
tell application "Photos"
activate
set imageSel to (get selection)
if (imageSel is {}) or (the length of imageSel < 2) then
error "Please select at least two images."
else
set lat to 0
set lon to 0
set haveLoc to false
set withLat to false
set withLon to false
set theLat to 0
set theLon to 0
repeat with i from 1 to count of imageSel
set this_image to item i of imageSel
tell this_image
set loc to get the location
set lat to (the first item of loc)
set lon to (the second item of loc)
set withLat to (lat is not equal to missing value)
set withLon to (lon is not equal to missing value)
-- display dialog "lat is " & lat & ", lon is " & lon
-- display dialog "withLat is " & withLat & ", withLon is " & withLon
if (withLat is not equal to withLon) then
error "An image has latitude or longitude bot not both"
end if
if (haveLoc and withLat) then
error "Multiple images already have a location"
end if
if (withLat) then
set haveLoc to true
set theLat to lat
set theLon to lon
end if
end tell
end repeat
repeat with i from 1 to count of imageSel
set this_image to item i of imageSel
tell this_image
set loc to get the location
set lat to (the first item of loc)
set lon to (the second item of loc)
if (lat is equal to missing value) then
-- display dialog "setting location to " & theLat & ", " & theLon
set the location to {theLat, theLon}
end if
end tell
end repeat
end if
end tell
The first and only piece of #AppleScript I have written. Very useful: Copy the geographic location metadata of one image in the #macOS #PhotosApp to a selection of other images that lack location information.
Script is available split into two pieces, as […]
[Original post on urbanists.social]