Getting DBUS Messages from Networkmanager (Python)
Dennis GuseI had some spare time and so I started playing with DBUS. I was annoyed that after NetworkManager established a connection I always start the same programs like ekiga, pidgin, firefox and evolution. So I wrote a small python program that start software if the NetworkManager singals an open connection via DBUS. The NetworkManager DBUS-API is available. The hardest part was to find the docs.
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
#!/usr/bin/python
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import dbus
import subprocess
def signal_deviceNowActive(data=None):
if data is not None and data[dbus.String("State")] == 2 :
subprocess.Popen("ps -C pidgin || pidgin &", shell=True)
subprocess.Popen("ps -C ekiga || ekiga &", shell=True)
subprocess.Popen("ps -C evolution || evolution &", shell=True)
print "init loop"
DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop();
print "init dbus"
dbus.SystemBus().add_signal_receiver(signal_deviceNowActive, signal_name=None, dbus_interface="org.freedesktop.NetworkManager.Connection.Active")
print "start loop"
loop.run() //*UPDATE: thanks for your comment