How to sort your photo based on GPS location, metadata of the image? This script & tweak will use Google Maps API, Hazel and photos import from your iPhone/smartphone with GPS enabled on that device.
Requirements
- Hazel installed
- Import photos from iPhone
- Google Maps API
Steps
- Put the iPhone photos into (Dropbox/IFTTT/TestGPS) folder.
- Create RULES in Hazel:
- If Latitude is greater than 0
- Run shell script EMBEDED Script
#Set Variable
#!/bin/bash
#apiKey="AIzaSyCEzXfCAwZLcqz90bn_mRPsvutwOoyIChI"
#apiKey="abcD12345efGhIJkLmn-abcD12345efGhIJkLmn_cO_8"
filename=$(basename “$1″)
filename=”${filename%.*}”
directoryname=$(dirname “$1”)
latitude=$(mdls “$1” | awk ‘/Latitude/ {print $3}’)
longitude=$(mdls “$1″ | awk ‘/Longitude/ {print $3}’)#Download JSON to local
curl -s https://maps.googleapis.com/maps/api/geocode/json?latlng=”$latitude”,”$longitude” > “$1.json”#Query local JSON – Short Name
#local6=$(curl -s http://localhost:8088/json/”$1.json” | jq ‘.results[0].address_components[6].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local6=$(cat “$1.json” | json ‘.results[0].address_components[6].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local5=$(cat “$1.json” | json ‘.results[0].address_components[5].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local4=$(cat “$1.json” | json ‘.results[0].address_components[4].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local3=$(cat “$1.json” | json ‘.results[0].address_components[3].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local2=$(cat “$1.json” | json ‘.results[0].address_components[2].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local1=$(cat “$1.json” | json ‘.results[0].address_components[1].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)
local0=$(cat “$1.json” | json ‘.results[0].address_components[0].short_name’ | sed -e ‘s/^”//’ -e ‘s/”$//’)if [ “$local6″ == MY ]
then
country=”$local6″
state=”$local5″
district=”$local4″
route=”$local3”
fi
if [ “$local5″ == MY ]
then
country=”$local5″
state=”$local4″
district=”$local3″
route=”$local2”
fi
if [ “$local4″ == MY ]
then
country=”$local4″
state=”$local3″
district=”$local2″
route=”$local1”
fi
if [ “$local3″ == MY ]
then
country=”$local3″
state=”$local2″
district=”$local1″
route=”${local0////_}”
fi
if [ “$local2″ == MY ]
then
country=”$local2″
state=”$local1″
district=”${local0////_}”
fidirectory_cs=$(“/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state”)
directory_d=$(“/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/$district”)
directory_r=$(“/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/$district””/$route”)if [ ! -d “$directory_cs” ]
then
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state”
fi
if [ ! -d “$directory_d” ]
then
#mkdir “$directory_d”
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district”
fi
if [ “$local6” == MY ]
then
if [ ! -d “$directory_r” ]
then
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/$route”
fi
if [ ! -f “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg” ]
then
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg”
else
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””_copy.jpg”
fi
elif [ “$local5” == MY ]
then
if [ ! -d “$directory_r” ]
then
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/$route”
fi
if [ ! -f “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg” ]
then
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg”
else
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””_copy.jpg”
fi
elif [ “$local4” == MY ]
then
if [ ! -d “$directory_r” ]
then
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/$route”
fi
if [ ! -f “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg” ]
then
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg”
else
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””_copy.jpg”
fi
elif [ “$local3” == MY ]
then
if [ ! -d “$directory_r” ]
then
mkdir “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/$route”
fi
if [ ! -f “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg” ]
then
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””.jpg”
else
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$route””/””$filename””_copy.jpg”
fi
else
if [ ! -f “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$filename””.jpg” ]
then
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$filename””.jpg”
else
mv “$1” “/Users/AmirMac/Pictures/DropboxLocationPictures/$country””_$state””/””$district””/””$filename””_copy.jpg”
fi
fi
rm “$1.json”
- Done