I am trying to launch the native Maps app and show a specific coordinate in OS X from my command line tool.
I've found three options:
- Use
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
- Use the
open
command and pass a formatted URL and let the system figure it out. - Use
NSTask
to launch Maps.app with the URL.
I tried the first one:
NSString *url = [NSString stringWithFormat:@"http://maps.apple.com/?q=%@&ll=%f,%f", user[@"realName"], geo.latitude, geo.longitude];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
(where it results in a perfectly valid string)
But it doesn't work. It just does nothing. Nothing opens, no errors, no warnings. Then I went to the second option. I couldn't figure out how to do the second, so I've turned up to NSTask
. I've found this answer: https://stackoverflow.com/a/412573/811405 and I've passed this URL as argument: http://maps.apple.com/?q=Example&ll=12.345,23.456
but I'm getting:
How can I open maps with a specific point from a Cocoa command line tool?