Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer

Well, I haven't gotten it to work... But might solve your issue....

This also seems to be a more stable package?

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

share|improve this answer
Both solutions seem to be broken on Mountain Lion. Did you manage to get it working somehow, or found something else working on OS X 10.8? I’m sure I am not the only one interested in this ... thanks! – myhd Dec 18 '12 at 21:32
I really haven't messed with it at this time. While being neat, I was really looking for a Find My iPhone type of code for portables. – Benjamin Schollnick Feb 25 '13 at 16:08
Thank you, I'm the author of CoreLocationCLI and just noting that it is moved to and has minor improvements since then – Full Decent Aug 27 '14 at 0:57

here you go

lynx -dump$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'

require lynx


share|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 '12 at 11:10

You must log in to answer this question.

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