Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Created May 13, 2017 10:12
Show Gist options
  • Save cmittendorf/b92bc84a9fd73013423aebe34502dcf1 to your computer and use it in GitHub Desktop.
Save cmittendorf/b92bc84a9fd73013423aebe34502dcf1 to your computer and use it in GitHub Desktop.
Copies the location information on macOS from one file to another.
#!/usr/bin/env bash
if [ $# != 2 ]; then
echo `basename $0`" <src file> <dst file>"
exit
fi
xattr -w "com.apple.metadata:kMDItemLatitude" $(mdls -name kMDItemLatitude "$1" | awk '{print $3}' | sed s/\"//g) "$2"
xattr -w "com.apple.metadata:kMDItemLongitude" $(mdls -name kMDItemLongitude "$1" | awk '{print $3}' | sed s/\"//g) "$2"
@BourneLoser
Copy link

When I look at the kMDItemLatitude & kMDItemLongitude attributes of an image file taken from my iPhone with GPS data, latitude & longitude are floating point data type. This copyLocationFromFile.sh script writes them as strings and consequently such files don't show in spotlight searches (example: Latitude is greater/less than 0). I'm still looking for a way to write them as floats with xattr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment