Currently Being Moderated

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

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 dialog panel_message buttons ¬

  "OK" with icon caution default button "OK"

 

-- copy the GPS data to the clipboard

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

set the clipboard to clipboard_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.

Replies

Delete User Tip

Are you sure you want to delete this user tip?