Script: Copy GPS tags from one Photo to Other Photos - 2018

by: 
Last modified: Dec 14, 2018 8:41 AM
3 1299 Last modified Dec 14, 2018 8:41 AM

While the location tags of a photo are read-only in Photos on Yosemite and El Capitan and cannot be changed by an Apple Script, it is now possible to change the latitude and longitude tags of selected photos from an Apple Script.

According to the AppleScript dictionary for Photos we should also be able to modify the altitude tag, but when I try to add an altitude value to a photo, it results in an error message.

But at least we now can copy the latitude and longitude from a photo and add it to other photos. The following Apple Script is an example for writing GPS to a photo.

You can use it like this:

  • Create an album with the photos you want to tag with GPS.
  • Add the photo you want to copy the GPS from as the first photo to this album.
  • Then select first the photo with the GPS coordinates, hold down the shift key and select the last photo in the album.


Now open the script in the Script Editor and click run.

All selected photos will have the same coordinates after this.


Try this first on a separate library for testing and make a backup of your main Photos Library

before you try batch changes this way.


You can also download a complied version of this script from Old Toad's site:

http://www.oldtoad.net/ASC/Copy%20GPS%20from%20one%20Photo%20to%20other%20Photos.zip


-- copy from the code block below this line -- snip -snip


(* Batch copy GPS from first photo to all other selected photos
How to use  this script:
- Collect all photos you want to set to the same GPS coordinates in an album
 and sort them manually
- The first photo should have a GPS location assigned
- Select first the photo with the correct location, 
  the hold down the Shift key and select all photos you want to set 
  to the same location at once. You need to select at least two photos.
- Open this script and run it by pressing the "Run" button.
- The script will copy the location from the first image 
  and set all photos to the same location

- if you save this script as an Application you can add it to the Dock 
 and run it from there


This script has been tested in Photos version 4.0, with MacOS X 10.14.2
and older versions of Photos.

© Léonie
*)   


(* select at least 2 images in Photos *)
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 withAlti to false
		set withLati to false
		set withLongi to false
		
		try
			tell the first item of imageSel
				set loc to get the location 
                  --retrieve longitude and latitude as list

				set alti to get the altitude -- retrieve the altitude
				
				set lati to (the first item of loc) -- as number
				set longi to (the second item of loc) -- as number
				
				--		return altiS
				set withAlti to (alti is not equal to missing value)
				set withLati to (lati is not equal to missing value)
				set withLongi to (longi is not equal to missing value)
				
				if not withLati then
					set withLati to false
					error "Photo has no Latitude assigned"
				end if
				
				if not withLongi then
					error "Photo has no Latitude assigned"
				end if
				if (lati > 90.0) or (lati < -90.0) then
					error "Latitude out of range " & lati
				end if
				if (longi > 180.0) or (longi < -180.0) then
					error "Longitude out of range " & longi
				end if
				
			end tell
		on error errTexttwo number errNumtwo
			display dialog "No GPS: " & errNumtwo & return & errTexttwo
			return
		end try
		
		if (not withLongi or not withLati) then
			
			return {loc, alti} --testing
		end if
		
		repeat with i from 2 to count of imageSel
			
			set next_image to item i of imageSel
			
			tell next_image
				set its location to {lati, longi}
				if withAlti then -- photo has altitude tag
					-- set its altitude to alti as number -- does not work
				end if
			end tell
			
			
		end repeat
	end if
	
	return {loc, alti, "Done"} -- for testing
end tell


The previous version of this script is here, but the formatting of the side is currently broken: Script: Copy GPS tags from one Photo to O… - Apple Community


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