Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Handling the GURL event triggered by OSX when it handles a URL scheme registered to an application.
import objc
NSAppleEventManager = objc.lookUpClass('NSAppleEventManager')
NSObject = objc.lookUpClass('NSObject')
class GURLHandler(NSObject):
def handleEvent_withReplyEvent_(self, event, reply_event):
url = event.descriptorForKeyword_(fourCharToInt('----')).stringValue()
# Do something with the url
# A helper to make struct since cocoa headers seem to make
# it impossible to use kAE*
fourCharToInt = lambda code: struct.unpack('>l', code)[0]
manager = NSAppleEventManager.sharedAppleEventManager()
GURLHandler.alloc(), 'handleEvent:withReplyEvent:',
fourCharToInt('GURL'), fourCharToInt('GURL')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.