-
-
Save sharoonthomas/6f5af82e347e94451d2e to your computer and use it in GitHub Desktop.
Handling the GURL event triggered by OSX when it handles a URL scheme registered to an application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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