Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created February 2, 2015 16:57
Show Gist options
  • Save loganwright/cb519c07934bee61cf30 to your computer and use it in GitHub Desktop.
Save loganwright/cb519c07934bee61cf30 to your computer and use it in GitHub Desktop.
osx url responder

Add Listener

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:shared
                                                   andSelector:@selector(handleURLEvent:withReplyEvent:)
                                                 forEventClass:kInternetEventClass
                                                    andEventID:kAEGetURL];

Respond to events

- (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
    NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    NSURL *url = [NSURL URLWithString:urlString];
    if ([GHAuth canHandleOpenUrl:url]) {
        [GHAuth handleOpenUrl:url];
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment