Is there a way to access OS X location services from the command line?

I'd like to be able to fetch OS X's current estimate of location from the the command-line so that I can script based on it. Is there a tool that does this?

I've found apps like locations that let you trigger actions based on location but I haven't found anything that let's you fetch the actual location data.


Solution 1:

I was looking for this, too, and failed to find one... So, I wrote one!

It's pretty simple at the moment, but it seems to basically work. I called it get-location, and you can get it from github (follow the link, above).

For the moment, I just print out the second location I receive from the service (I skip the first one, since it can be cached and old – in a future version, perhaps this will be configurable, or it's an easy hack (change the hits check to be > 0, instead of > 1) in the code, if you don't want to wait for that (I may or may not change it soon).

Anyway, it then prints out the results, like so (note: location data here has been changed to something made up):

$ ./get-location
Final location: <+12.34567890, +12.34567890> +/- 176.00m (speed 0.00 mps / course -1.00) @ 2012-04-10 13:57:53 +0200

Another TODO item is to add other formats, and/or let you specify your own. I may add this soon, or I may add it later. Or: Send me a pull request. :) (Feature requests and bug reports also welcome, preferably via the github system. Also, check the README on github to see what I've already thought of.)

I hope you (and others) find this helpful.

EDIT: Now with command-line options and a few different output formats.

Solution 2:

Well, I haven't gotten it to work... But http://code.google.com/p/corelocationcli/ might solve your issue....

This also seems to be a more stable package? http://iharder.sourceforge.net/current/macosx/locateme/

(The issue I am having with both, might be because I am trying these on Mountain Lion.... )

While not built-ins, they both appear to use CoreLocation services....