Create a gist now

Instantly share code, notes, and snippets.

Embed
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()
manager.setEventHandler_andSelector_forEventClass_andEventID_(
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