Script: Assign the Same GPS Coordinates to Several Selected Items in Photos
Currently it is not possible to assign precise GPS coordinates to a photo or video in Photos. Even if we enter a pair of latitude and longitude as a location into the Info, Photos will assign the location the closest named place, which can be thousands of kilometres off in sparse populated areas.
The script below will assign the location exactly as entered as a latitude in degrees and a longitude in degrees.
- Select several photos videos together, that should have the same location in Photos in the All Photos album or a top level album
- Run the script in Script Editor by pressing the Run button ▶︎
- and when asked enter first the latitude in degrees, then the longitude.
- Use negative numbers for southern latitudes and western longitudes.
Copy and paste the code below into a new AppleScript with Script Editor and save it:
--- snip -snip --- copy the code below this line
-- Author: Léonie © 2020
-- To use this script select several photos in Photos in a top level album or in All photos, that should be assigned to the same location.
-- When prompted, enter the latitude in degrees and the longitude in degrees as real numbers. Use the minus sign to southern latitudes and western longitudes
set imageSel to {}
tell application "Photos"
activate
--check for selected images
try
set imageSel to (get selection)
set im to item 1 of imageSel
set currentfilename to the filename of im as text
on error errTexttwo number errNumtwo
display dialog "Cannot get the selection: Please select a photo in All Photos or azop level album" & errNumtwo & return & errTexttwo
end try
-- ask the user for the GPS coordinates, first latitude, then longitude
set newlatitude to (text returned of (display dialog "Changeing the GPS coordinates of image " & currentfilename & ". Enter the new latitude in degrees: (negative for southern latitudes)" default answer 0.0 buttons {"OK"} default button "OK")) as real
set newlongitude to (text returned of (display dialog "Enter the new longitude in degrees: (negative for western longitudes)" default answer 0.0 buttons {"OK"} default button "OK")) as real
set loc to {newlatitude, newlongitude}
-- write the GPS to all selected images
set the item_count to count of imageSel
repeat with i from 1 to the item_count
set im to item i of imageSel
set currentfilename to the filename of im as text
try
set the location of im to loc
on error errTexttwo number errNumtwo
display dialog "Cannot set the location: " & (currentfilename & " " & newlatitude & " " & newlongitude) & errNumtwo & return & errTexttwo
end try
spotlight im -- Show the image
end repeat
end tell
return (currentfilename & " " & newlatitude & " " & newlongitude)