2

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.

  • 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 using exiftool however you'd have to install it. If you'd provide more information about what your trying to do and be a bit more explicit and specific it would be easier to write up and answer. – user3439894 Feb 1 '17 at 5:23
  • @user3439894 Looks Good. Can you change your comment into an answer so I can accept it? – Manngo Feb 1 '17 at 5:31
  • I can however do you need any additional information or are you good with just what I've said? – user3439894 Feb 1 '17 at 5:36
  • @user3439894 You comment answered the question I asked, so that should be enough. However, if you happen to know how to use the -nullMarker option (it doesn’t seem t work for me, even when I use the raw option), or whether there is an alternative for RAW files, that would be a bonus. Otherwise, it’s good. – Manngo Feb 1 '17 at 5:53
1

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 using exiftool however you'd have to install it.

To answer the question in your comment:

If you query an attributeName when using -raw and the attributeName 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"

mdls -name kMDItemFake -raw -nullMarker "Does Not Exist" /path/to/photo

In the example command above kMDItemFake is a fake kMDItem 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 using mdls -name kMDItemLatitude -raw. To change that, use −nullMarker markerString.

If a kMDItem doesn't exist and you want no output when using mdls -name attar -raw then use mdls -name attar -raw −nullMarker '' /path/to/photo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .