Permalink
Browse files

Added skype.py.

  • Loading branch information...
1 parent 813e512 commit cfbc7427dbafe74796bc16f7ef538f0c364feb1a @jgm committed Nov 6, 2010
Showing with 92 additions and 0 deletions.
  1. +3 −0 README
  2. +89 −0 skype.py
View
3 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
View
@@ -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
+

0 comments on commit cfbc742

Please sign in to comment.