Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script: Copy GPS tags from one Photo to Other Photos

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.


(* Batch change the time of selected photos all at once


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 2.0, with MacOS X 10.12.2


© 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 errTexttwonumbererrNumtwo

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 itemi of imageSel


tell next_image

set its location to {lati, longi}


-- if withAlti then -- photo has altitude tag


-- set its altitude to alti


-- end if

end tell

if withAlti then -- photo has altitude tag

tell next_image


-- set its altitude to alti as number -- does not work

end tell

end if



end repeat

end if


return {loc, alti, "Done"} -- for testing

end tell

MacBook Pro (Retina, 15-inch, Mid 2015), macOS Sierra (10.12.2), 2,8 GHz Intel Core i7, 16 GB, 1TB

Posted on Jan 22, 2017 7:18 AM

Reply
Question marked as Best reply

Posted on Jan 22, 2017 11:37 AM

Does the script work for your library?

I managed to copy the script to the User Tip section by now. For some weird reason my link to the user tips is now taking me to the regular forum and hanging eternally while redirecting the link 😠

The published script is now here:

Script: Copy GPS tags from one Photo to Other Photos

8 replies
Question marked as Best reply

Jan 22, 2017 11:37 AM in response to Old Toad

Does the script work for your library?

I managed to copy the script to the User Tip section by now. For some weird reason my link to the user tips is now taking me to the regular forum and hanging eternally while redirecting the link 😠

The published script is now here:

Script: Copy GPS tags from one Photo to Other Photos

Script: Copy GPS tags from one Photo to Other Photos

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