Music Player Daemon Community Wiki

Bind notebook media keys to MPD using DBUS

522pages on
this wiki
Add New Page
Talk0 Share
#!/usr/bin/env python
This script handles media key pressing events on DBus
(Fn+Play/Pause/Stop/Forward/Prev) by calling mpc with
corresponding argument.
Tested on Acer aspire 3935 with Ubuntu 10.10. Both laptop
media keys and bluetooth stereo garniture media buttons (BT56) work.

Author: Batalov Sergey, 2011-02-07 svbatalov at gmail dot com.

Here is a patch to use it with (see ):
@@ -99,9 +99,13 @@
-            "previous"
+           "previous",
+            "prev"
+    def prev(self):
+       self.previous()
     def info(self):
         Show song information only

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import os

mpc = 'mpc'   # Or modified to accept the 'prev' command.
def KeyHandler(x,y):
	def run(cmd):
		return lambda: os.system(mpc + ' ' + cmd)
	'Play': run('toggle'),
	'Stop': run('stop'),
	'Next': run('next'),
	'Previous': run('prev')	}[y]()

bus = dbus.SessionBus()
loop = gobject.MainLoop()

#dbus info obtained using dbus-monitor
		None,                                   #signal name. None means any
		'org.gnome.SettingsDaemon.MediaKeys',   #interface
		None, 			           	#sender bus name. any. :1.7 usually
		'/org/gnome/SettingsDaemon/MediaKeys'   #path

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.