diff --git a/README.md b/README.md index 9dcc990..3cd4f2a 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ The following are currently supported: * Getting the installed firmware versions * Installing firmware * Getting device data (serial, BT MAC etc) +* Remote support for Keynote and iTunes REPL ---- diff --git a/p.py b/p.py index 53bb407..8f9a6eb 100755 --- a/p.py +++ b/p.py @@ -54,6 +54,12 @@ def cmd_get_time(pebble, args): def cmd_set_time(pebble, args): pebble.set_time(args.timestamp) +def cmd_remote(pebble, args): + pebble.remote(args.app) + #keep open to receive remote events + while True: + time.sleep(1) + def main(): parser = argparse.ArgumentParser(description='a utility belt for pebble development') parser.add_argument('--pebble_id', type=str, help='the last 4 digits of the target Pebble\'s MAC address') @@ -102,6 +108,10 @@ def main(): set_time_parser.add_argument('timestamp', type=int, help='time stamp to be sent') set_time_parser.set_defaults(func=cmd_set_time) + remote_parser = subparsers.add_parser('remote', help='remote control Mac applications') + remote_parser.add_argument('app', metavar='APP', choices=('itunes', 'keynote', 'powerpoint'), type=str, help='either itunes or keynote') + remote_parser.set_defaults(func=cmd_remote) + args = parser.parse_args() attempts = 0 diff --git a/pebble/pebble.py b/pebble/pebble.py index 807146c..503f128 100755 --- a/pebble/pebble.py +++ b/pebble/pebble.py @@ -108,6 +108,69 @@ class Pebble(object): to the watch through an instance of this class. """ + _remote_commands = { + "ITUNES": [ + """ + osascript -e 'tell application "System Events" + tell application "iTunes" to activate + key code 49 + end tell' + """, + """ + osascript -e 'tell application "System Events" + tell application "iTunes" to activate + key code 124 using command down + end tell' + """, + """ + osascript -e 'tell application "System Events" + tell application "iTunes" to activate + key code 123 using command down + end tell' + """ + ], + "KEYNOTE": [ + """ + osascript -e 'tell application "System Events" + tell application "Keynote" to activate + key code 35 using {command down, option down} + end tell' + """, + """ + osascript -e 'tell application "System Events" + tell application "Keynote" to activate + key code 124 using command down + end tell' + """, + """ + osascript -e 'tell application "System Events" + tell application "Keynote" to activate + key code 123 using command down + end tell' + """ + ], + "POWERPOINT": [ + """ + osascript -e 'tell application "Microsoft PowerPoint" + activate + run slide show slide show settings of active presentation + end tell' + """, + """ + osascript -e 'tell application "Microsoft PowerPoint" + activate + go to next slide slide show view of slide show window 1 + end tell' + """, + """ + osascript -e 'tell application "Microsoft PowerPoint" + activate + go to previous slide slide show view of slide show window 1 + end tell' + """ + ] + } + endpoints = { "TIME": 11, "VERSION": 16, @@ -156,7 +219,8 @@ def __init__(self, id = None): self.endpoints["SYSTEM_MESSAGE"]: self._system_message_response, self.endpoints["LOGS"]: self._log_response, self.endpoints["PING"]: self._ping_response, - self.endpoints["APP_MANAGER"]: self._appbank_status_response + self.endpoints["APP_MANAGER"]: self._appbank_status_response, + self.endpoints["MUSIC_CONTROL"]: self._remote_response } try: @@ -168,6 +232,8 @@ def __init__(self, id = None): # we get a null response when we connect, discard it self._ser.read(5) + self._ser.write("\x00\x0d\x00\x11\x01\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x32") + # Eat any cruft that might be sitting in the serial buffer... while self._ser.read(): pass @@ -467,6 +533,29 @@ def disconnect(self): self._alive = False self._ser.close() + def remote(self, remote_app): + app_string = { + "ITUNES" : "iTunes", + "KEYNOTE" : "Keynote", + "POWERPOINT" : "PowerPoint" + } + self._remote_app = remote_app.upper() + log.info("Remote: Control " + app_string[self._remote_app] + " with Pebble" ) + self.set_nowplaying_metadata(app_string[self._remote_app], "libpebble", "Pebble") + + + def _remote_response(self, endpoint, data): + res, = unpack("!b", data) +# log.info("Remote: %s" % res) + cmd = "" + if res == 1: + cmd = self._remote_commands[self._remote_app][0] + elif res == 4: + cmd = self._remote_commands[self._remote_app][1] + elif res == 5: + cmd = self._remote_commands[self._remote_app][2] + os.system(cmd) + def _add_app(self, index): data = pack("!bI", 3, index) self._send_message("APP_MANAGER", data)