Friday 7 December 2012

Media Buttons on Mint 14 Nadia

Sadly keyboard multi-media control buttons still have no effect on Mint 14 when logged in using the Gnome2 fork Mate desktop.

Gladly, Matteo Italia has written a short python script to convert the DBUS events into MPRIS2 events.

Start the script on login and media keys work! Thanks Matteo

#!/usr/bin/env python

Created on 30.05.2012

@author: Matteo Italia <>

import dbus
import dbus.mainloop.glib
import gobject

app_name = 'mmkeys-mate2mpris2'

MediaKeysObjName = 'org.mate.SettingsDaemon'
MediaKeysObjectPath = '/org/mate/SettingsDaemon/MediaKeys'
MediaKeysInterface = 'org.mate.SettingsDaemon.MediaKeys'

MPRIS2Prefix = 'org.mpris.MediaPlayer2'

ActionMappings = {
        'Play': 'PlayPause',
        'Pause': 'Pause',
        'Stop': 'Stop',
        'Next': 'Next',
        'Previous': 'Previous'}

def onMediaKeyPress(app_name, action):
    sb = dbus.SessionBus()
    # Get the compatible players
    players = [n for n in sb.list_names() if n.startswith(MPRIS2Prefix + ".") ]

    # Send them the command
    for n in players:
        # TODO: it doesn't make sense to perform the action on *all* the players!
        # find a sensible criterion to choose the "best one"
        sb.get_object(n, '/org/mpris/MediaPlayer2').__getattr__(ActionMappings[action])()

if __name__ == '__main__':

    # DBUS boilerplate
    sb = dbus.SessionBus()

    # Get the media keys notificator object
    mediaKeysObj = sb.get_object(MediaKeysObjName, MediaKeysObjectPath)

    # Register to receive media keys notifications
    mediaKeysObj.GrabMediaPlayerKeys(app_name, 0, dbus_interface=MediaKeysInterface)
    mediaKeysObj.connect_to_signal('MediaPlayerKeyPressed', onMediaKeyPress)

    # Start the main loop
    mainLoop = gobject.MainLoop()


  1. I get an error

    DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "Next" with signature "" on interface "(null)" doesn't exist

    Do you perhaps understand it?

    1. Maybe it was a cut-n-paste error from this web-page? Try getting the text directly from the pastebin link?