Script: Assign GPS Coordinates to an Item in Photos

by: 
Last modified: Nov 23, 2020 6:16 AM
2 829 Last modified Nov 23, 2020 6:16 AM

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 a photo 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 and paste from here

set imageSel to {}

-- Author: Léonie © 2020
-- To use this script select a photo in Photos in a top level album or in All photos.
-- 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
tell application "Photos"
	activate
	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
	
	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}
	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 tell

return (currentfilename & " " & newlatitude & " " & newlongitude)

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