Rdio and Linux

Posted on 2014-04-22 in linux • 3 min read

I have been using [Rdio](http://www.rdio.com) for about a year now. While it has some holes with older music, all-in-all I am very happy with the service.

Rdio uses a very capable web player so you can play your music in your browser.  That's perfect, however the one thing missing is support for multimedia keys.  After searching around for a Linux app that supported multimedia keys, I discovered that I could roll my own very easily using chrome, xbindkeys, and xdotool.

xbindkeys and xdotool

These two apps are the heart of what makes this work.  xbindkeys grabs the input keys, and executes xdotool which let's us operate on specific windows and send key strokes to them.  So they both need to be installed first.  I am using Fedora, but I presume these exist as packages in whatever Linux you are using.

sudo yum -y install xbindkeys xdotool

Chrome

The first thing is to create an "application shortcut" for chrome.  Do this by doing the following:

  1. Open Chrome
  2. Browse to <http://rdio.com>
  3. Click the tool icon thingy (three lines in the upper-right)
  4. Click Tools
  5. Click "Create Application Shortcuts"
  6. Choose where you want the shortcut to go.  Really we are just looking for it to create the .desktop entry so that it will show up in Gnome's overlay mode so the default Desktop is all that's needed.

At this point there is a perfectly functional webpage acting like an application.  It should run if you hit the SUPER key and type rdio.

Xbindkeys Config

Below is my current config file.  In order to get the keys to send, you need to run

xbindkeys -mk

This will run xbindkeys in a window, make sure that window is active and hit the key you want to bind.  The code for that key will then show in the console.  Then you just write the config with the command that you want to be run, followed by the key (that we grabbed before).  This is where xdotool comes in.  We are going to search for a window named Rdio, and send the keys that perform the multimedia functions.  So for example, when we hit the media key Play/Pause, it will send a space to the window named Rdio.

#keystate_numlock = enable #keystate_capslock = enable #keystate_scrolllock= enable

#Media keys for my fake rdio app (chrome --app) "$(grep '^Exec' rdio.desktop | tail -1 | sed 's/^Exec=//' | sed 's/%.//')"     Mod2 + XF86AudioMedia "xdotool key --window $(xdotool search --limit 1 --name Rdio) space"     Mod2 + XF86AudioPlay "xdotool key --window $(xdotool search --limit 1 --name Rdio) Left"     Mod2 + XF86AudioPrev "xdotool key --window $(xdotool search --limit 1 --name Rdio) Right"     Mod2 + XF86AudioNext

Gnome Configuration

By default, Gnome is going to have the keys bound to some multimedia key default.  And they are probably the same ones you are trying to bind. So you have to disable the Gnome keybindings so xbindkeys can grab them instead.  To do this:

  • Go to settings
  • Either by clicking the icons in the upper-right hand side and clicking the tools icon
  • or...hit the SUPER key to go to overlay mode and search for settings
  • Choose the keyboard under Hardware
  • Click the Shortcuts tab
  • Click "Sound and Media"
  • Go to each key you want to grab from xbindkeys and when it prompts you for "new accelerator" you can either hit Backspace to clear the setting.

Success! (hopefully)

At this point you should have a fully functional web app that responds to multimedia keys.

<menu id="wanikanify-menu" type="context"> <menu label="WaniKanify"> </menu> </menu> <menu id="wanikanify-menu" type="context"> <menu label="WaniKanify"> </menu> </menu>