From cfbc7427dbafe74796bc16f7ef538f0c364feb1a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 5 Nov 2010 20:51:13 -0700 Subject: [PATCH] Added skype.py. --- README | 3 ++ skype.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100755 skype.py diff --git a/README b/README index 3a858e1..b8b27e2 100644 --- a/README +++ b/README @@ -33,6 +33,9 @@ repeat s3sh a wrapper around the s3sh gem +skype.py + interact with skype from command line + texdiff.pl diff for TeX files diff --git a/skype.py b/skype.py new file mode 100755 index 0000000..396bc79 --- /dev/null +++ b/skype.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +# Interact with skype from the command line, using skype API +# +# skype toggle +# skype hide +# skype answer +# skype hangup +# skip call [number] + +import sys +import traceback +import re + +import dbus +import dbus.service +#for event loop +import gobject +from dbus.mainloop.glib import DBusGMainLoop + +####################################################### +#catching the events +class Callback_obj(dbus.service.Object): + def __init__(self, bus, object_path): + dbus.service.Object.__init__(self, bus, object_path, bus_name='com.Skype.API') + + @dbus.service.method(dbus_interface='com.Skype.API') + def Notify(self, message_text): + pass + +###################################################### + +args = sys.argv + +if len(sys.argv) > 1: + command = sys.argv[1].lower() +else: + command = "toggle" + +arguments = sys.argv[2:] + +dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + +#connect to the session +session_bus = dbus.SessionBus() + +#connect to Skype +skype = session_bus.get_object('com.Skype.API', '/com/Skype') + +#ok lets hit up skype now! +answer = skype.Invoke('NAME PythonManageCall') +if answer != 'OK': + sys.exit('Could not bind to Skype client') +answer = skype.Invoke('PROTOCOL 5') +if (answer != 'PROTOCOL 5'): + sys.exit('Could not agree on protocol!') + +#tie up the events to the skype +skype_callback = Callback_obj(session_bus, '/com/Skype/Client') + +if command == "toggle": + state = skype.Invoke('GET WINDOWSTATE') + if state == 'WINDOWSTATE HIDDEN': + skype.Invoke('SET WINDOWSTATE NORMAL') + else: + skype.Invoke('SET WINDOWSTATE HIDDEN') +elif command == "hide": + skype.Invoke('SET WINDOWSTATE HIDDEN') +elif command == "answer": + answer = skype.Invoke('SEARCH ACTIVECALLS') #get calls going on right now! + if(re.search(r'CALLS [0-9]+', answer)): # see if there was a call + callNum = re.search(r'CALLS ([0-9]+)', answer).group(1) + print 'Answering Call ', callNum + skype.Invoke('SET CALL ' + callNum + ' STATUS INPROGRESS') +elif command == "hangup": + answer = skype.Invoke('SEARCH ACTIVECALLS') #get calls going on right now! + if(re.search(r'CALLS [0-9]+', answer)): # see if there was a call + callNum = re.search(r'CALLS ([0-9]+)', answer).group(1) + print 'Answering Call ', callNum + skype.Invoke('SET CALL ' + callNum + ' STATUS FINISHED') +elif command == "call": + if len(arguments) < 1: + print 'You need to specify a number to call.' + exit + else: + skype.Invoke('CALL ' + ', '.join(arguments)) +else: + print "Unknown command: ", command +