Check if Rhythmbox works through Python

I am trying to extract information from Rhythmbox via dbus , but I only want to do this if Rhythmbox is running. Is there a way to check if Rhythmbox works through Python without starting it if it doesn't work?

Whenever I call the dbus code as follows:

 bus = dbus.Bus() obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell") iface = dbus.Interface(obj, "org.gnome.Rhythmbox.Shell) 

and Rhythmbox is not running, it starts it.

Is it possible to check via dbus if the Rhythmbox works without actually starting it? Or is there any other way, besides parsing the list of running processes, to do this?

+4
source share
2 answers

This is similar to Roche Oxymoron's answer, but perhaps neat (albeit untested):

 bus = dbus.SessionBus() if bus.name_has_owner('org.gnome.Rhythmbox'): # ... 

If you want to be notified when the Rhythmbox starts or stops, you can use:

 def rhythmbox_owner_changed(new_owner): if new_owner == '': print 'Rhythmbox is no longer running' else: print 'Rhythmbox is now running' bus.watch_name_owner('org.gnome.Rhythmbox') 

See the documentation for dbus.bus.BusConnection for more information .

+5
source
 dbus_main_object = bus.get_object("org.freedesktop.DBus", "/") dbus_names = dbus_main_object.ListNames(dbus_interface='org.freedesktop.DBus') if 'org.gnome.Rhythmbox' in dbus_names: do_whatever() 
+1
source

Source: https://habr.com/ru/post/1334766/


All Articles