I was looking around for a solution to pause Rhythmbox whenever I lock my screen, and to continue playing when I return. Looking around the intarwebs, I found a blog post with a basic Python script.
I changed some aspects of that script to suit my needs, namely:
UPDATE: With Ubuntu 11.10, Rhythmbox changed to the MPRIS interface — I adapted the script accordingly.
So without further ado, here’s my version of it:
#!/usr/bin/python import dbus import dbus.glib import gobject paused = False def screensaver_changed(state): """This method is called when the screensaver starts/stops """ global paused if session_bus.name_has_owner('org.mpris.MediaPlayer2.rhythmbox'): proxy = session_bus.get_object('org.mpris.MediaPlayer2.rhythmbox', '/org/mpris/MediaPlayer2') player = dbus.Interface(proxy, 'org.mpris.MediaPlayer2.Player') props = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties') if state and props.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') == "Playing": paused = True player.Pause() elif not state and paused: paused = False player.Play() session_bus = dbus.SessionBus() session_bus.add_signal_receiver(screensaver_changed,'ActiveChanged','org.gnome.ScreenSaver') loop = gobject.MainLoop() loop.run()