Last active
August 29, 2015 14:03
-
-
Save winny-/33df3e09243717dc083f to your computer and use it in GitHub Desktop.
Play/pause Hermes when in a skype call. See this issue for details on usage: https://github.com/HermesApp/Hermes/issues/183 remote.applescript is based off of: https://github.com/winny-/HermesRemote/blob/master/api/_scripts/status.applescript
This file contains hidden or 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
#!/usr/bin/env python | |
import Skype4Py | |
import subprocess | |
import time | |
import sys | |
import argparse | |
please_resume = None | |
def attach_hermes_control(resume=True, timeout=5000): | |
global please_resume | |
please_resume = resume | |
skype = Skype4Py.Skype() | |
skype.Timeout = timeout | |
skype.Attach() | |
skype.OnCallStatus = on_call_status | |
return skype | |
def main(): | |
parser = argparse.ArgumentParser(description='Automatically start/stop Hermes playback on Skype call start/end') | |
parser.add_argument('--no-resume', action='store_false', help='Do not resume playback after a Skype call hang up') | |
args = parser.parse_args() | |
sys.stdout.write('Connecting:') | |
sys.stdout.flush() | |
skype = None | |
while skype is None: | |
try: | |
skype = attach_hermes_control(resume=args.no_resume) | |
except Skype4Py.errors.SkypeAPIError: # Skype is not running, wait. | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
time.sleep(1) | |
print(' connected!') | |
print('Skype is attached. Sleeping forever.') | |
while True: | |
time.sleep(10) | |
def on_call_status(call, status): | |
global please_resume | |
command = None | |
if status == Skype4Py.clsInProgress: | |
command = 'pause' | |
print('Call started.') | |
elif status == Skype4Py.clsFinished: | |
if please_resume: | |
command = 'play' | |
print('Hung up.') | |
if command: | |
subprocess.call(['osascript', 'remote.applescript', command]) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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
on is_running(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end is_running | |
on parse_arguments(argv) | |
set arguments to "" | |
repeat with arg in argv | |
set arguments to arguments & " " & arg | |
end repeat | |
return arguments | |
end parse_arguments | |
on run argv | |
set arguments to parse_arguments(argv) | |
if arguments ≠ "" and arguments ≠ " " then | |
if is_running("Hermes") then | |
set script_text to "Tell Application \"Hermes\" to " & arguments | |
run script {script_text} | |
end if | |
end if | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment