Reputation: 11
Now I want to write a little CLI application which can get the custom scheme url to do something like launch some other apps. I found a method, Firstly, edit the 'info.plist' add a 'URL Schemes' under 'URL types', for example I add a 'mySchemes' item. Secondly, install a event handler in 'AppDelegate',
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
-(void) handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"%@",url);
// Do something next
}
But I want to implement it in a command line application, how can I get this event without cocoa framework? I don't need UI
Upvotes: 0
Views: 405
Reputation: 1542
Setting LSUIElement
in your Info.plist will allow you to run your app without a UI. From Apple's Information Property List Key Reference:
If this key is set to YES, Launch Services runs the app as an agent app. Agent apps do not appear in the Dock or in the Force Quit window. Although they typically run as background apps, they can come to the foreground to present a user interface if desired. A click on a window belonging to an agent app brings that app forward to handle events.
Upvotes: 1