I am trying to write an Automator Script which involves, among other things, getting the GPS location data from an image. This will be a Finder Service.
From what I have been able to discover so far, it involves running some AppleScript and talking to the Image Events
headless application.
From here, how do I actually get the Latitude & Longitude of the image?
I know there are applications which can read this data, including on the command line, but I wondered whether it was available to MacOS without adding anything.
Best Answer
I do not believe Image Events is able to get that type of meta data from the photo however
mdls
can do it, e.g.mdls -name kMDItemLatitude -name kMDItemLongitude /path/to/photo
however it all depends what exactly your trying to do with this info. I personally prefer usingexiftool
however you'd have to install it.To answer the question in your comment:
If you query an
attributeName
when using-raw
and theattributeName
doesn't exist the output is literally(null)
and if you want it to be something else then use−nullMarker markerString
, e.g.:−nullMarker "Does Not Exist"
In the example command above
kMDItemFake
is a fakekMDItem
item, so that command will output:Does Not Exist
instead of(null)
.In other words, if as example the photo doesn't have
kMDItemLatitude
info and you query for it the output will be(null)
when usingmdls -name kMDItemLatitude -raw
. To change that, use−nullMarker markerString
.If a
kMDItem
doesn't exist and you want no output when usingmdls -name attar -raw
then usemdls -name attar -raw −nullMarker '' /path/to/photo
.