Required tools:
Exiftool -- http://www.sno.phy.queensu.ca/~phil/exiftool/
JSON helper plugin for Applescript - https://itunes.apple.com/us/app/json-he ... 4608?mt=12
You will also need to sign up for an API key from google here: https://developers.google.com/maps/docu ... g/#api_key
The scrip is below. Note that 1) script assumes exiftool is installed in /usr/bin/ and 2) you will need to input your own API key in the middle of the script where it says to do so.
I have not tested this extensively but it has worked without error the last week.
- Code: Select all
set ExifTool to "/usr/bin/exiftool"
set ExifGPSLat to "-GPSLatitude"
set ExifGPSLon to "-GPSLongitude"
set ExifToolOption to "-keywords+="
-- Get file path
try
set pathList to quoted form of POSIX path of (theFile as alias)
end try
-- Get GPS Latitude and Longitude from EXIF data
do shell script ExifTool & space & ExifGPSLat & space & "-overwrite_original_in_place -P" & space & pathList
set gpsLat to result
do shell script ExifTool & space & ExifGPSLon & space & "-overwrite_original_in_place -P" & space & pathList
set gpsLon to result
if (gpsLat = "") or (gpsLon = "") then
error number -128
else
-- Set GPS variables separately
set latDegree to word 3 of gpsLat
set latMinute to word 5 of gpsLat
set latSecond to word 6 of gpsLat
set latDirection to word 7 of gpsLat
set lonDegree to word 3 of gpsLon
set lonMinute to word 5 of gpsLon
set lonSecond to word 6 of gpsLon
set lonDirection to word 7 of gpsLon
-- Convert Deg,Sec,Min to Decimals
set latDecimal to latDegree + latMinute / 60 + latSecond / 3600
set lonDecimal to lonDegree + lonMinute / 60 + lonSecond / 3600
-- Change Decimals based on Direction
if (latDirection is equal to "S") then
set latDecimal to latDecimal * -1 as text
end if
if (lonDirection is equal to "W") then
set lonDecimal to lonDecimal * -1 as text
end if
set locateP to latDecimal & "," & lonDecimal as string
-- Set the Google API variables
set api_key to "ENTER_YOUR_OWN_KEY_HERE"
set apiCommand to "https://maps.googleapis.com/maps/api/geocode/json?latlng=" & locateP & "&result_type=street_address&key=" & api_key
-- Fetch location information from Google
try
tell application "JSON Helper"
set geoL to apiCommand
set jsonResult to fetch JSON from geoL with cleaning feed
set kWord to formatted_address of item 1 of results of jsonResult
end tell
end try
-- Add keywords for location for images
do shell script ExifTool & space & ExifToolOption & quoted form of kWord & space & "-overwrite_original_in_place -P" & space & pathList
end if