#!/usr/bin/env python # vim: set expandtab shiftwidth=4 tabstop=4: # # Jacek Fedorynski # http://www.jfedor.org/ # import AppKit import objc import appscript class AppleRemoteDelegate(AppKit.NSObject): mapping = { 64: 123, 32: 124, 2: 126, 4: 125, 8: 53, 16: 96 } @objc.signature("v@:ii^@") def sendRemoteButtonEvent_pressedDown_remoteControl_(self, event, pressedDown, remoteControl): if pressedDown and event in self.mapping: appscript.app('System Events').key_code(self.mapping[event]) objc.loadBundle('AppleRemote', globals(), bundle_path=objc.pathForFramework(u'../Frameworks/AppleRemote.framework')) d = AppleRemoteDelegate.alloc().init() a = AppleRemote.alloc().initWithDelegate_(d) if a is None: raise Exception('There was an error, does your Mac have a remote?') a.startListening_(d) AppKit.NSApplication.sharedApplication().run()