Script: Retrieve the GPS Coordinates of the Place of a Photo

by: 
Last modified: Sep 21, 2016 6:13 AM
1 973 Last modified Sep 21, 2016 6:13 AM

iPhoto does display the name of location in the Info panel for a photo, but not the GPS coordinates.

This is a simple script that will copy the latitude and longitude for a selected image in iPhoto to the clipboard and display a panel with the values.


-- This script will display the GPS values a selected photo in a dialog panel.

-- The coordinates will be copied to the clipboard


on ensure_val(the_value, default_value)


-- if the_value is defined return the value, otherwise the default value

if the_value is equal to "missing value" then

return default_value

else

return the_value

end if

end ensure_val


-- on run {}

tell application "iPhoto"


activate


set imageSel to (get selection) -- get the selected image


if imageSel is {} then

error "Please select an image."

end if

tell the first item of imageSel

set lati to its latitude as string

set longi to its longitude as string


-- set alti to get the altitude as string -- retrieve the altitude

end tell


end tell


-- check for undefined values

set lati to ensure_val(lati, "latitude empty")

set longi to ensure_val(longi, "longitude empty")


-- display the result in a dialog panel

set panel_message to "Latitude: " & lati & "

Longitude: " & longi & " Copied to the clipboard"

display dialogpanel_messagebuttons ¬

"OK" with iconcautiondefault button "OK"


-- copy the GPS data to the clipboard

set clipboard_message to " " & lati & " " & longi

set the clipboard toclipboard_message


return clipboard_message


-- end run



Copy and paste this script into a Script Editor window, select a photo in iPhoto, then click the Run button in Script Editor. You should see a panel with the coordinates apper, that you need to dismiss.

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