493: Undecipherable

-About me-

-Projects-

Getting DBUS Messages from Networkmanager (Python)

Dennis Guse

I 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 #!/usr/bin/python
 2 from dbus.mainloop.glib import DBusGMainLoop
 3 import gobject
 4 import dbus
 5 import subprocess
 6 
 7 def signal_deviceNowActive(data=None):
 8   if data is not None and data[dbus.String("State")] == 2 :
 9     subprocess.Popen("ps -C pidgin    || pidgin &", shell=True)
10     subprocess.Popen("ps -C ekiga     || ekiga &", shell=True)
11     subprocess.Popen("ps -C evolution || evolution &", shell=True)
12 
13 print "init loop"
14 
15 DBusGMainLoop(set_as_default=True)
16 
17 loop = gobject.MainLoop();
18 
19 print "init dbus"
20 
21 dbus.SystemBus().add_signal_receiver(signal_deviceNowActive, signal_name=None, dbus_interface="org.freedesktop.NetworkManager.Connection.Active")
22 
23 print "start loop"
24 
25 loop.run() //*UPDATE: thanks for your comment