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.

link|improve this question
feedback

3 Answers

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.

link|improve this answer
feedback

here you go

lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'

require lynx

source

link|improve this answer
Nota bene: This is not the same thing. Potentially useful, but not the same thing. In particular, this requires having full internet access, whereas CoreServices I believe can run without that, as long as wifi is enabled. And anyway, even if I'm wrong about that, it uses WIFI-based location finding (and anything else CoreLocation might use, now or in the future), rather than just IP address, which is potentially much more accurate. (See, e.g., here.) – lindes Apr 10 at 11:10
feedback

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....

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.