-
Notifications
You must be signed in to change notification settings - Fork 3
/
skype.py
executable file
·89 lines (73 loc) · 2.53 KB
/
skype.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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