Using OS X Media Keys With Web Applications
Last week I set out to find a way to use my macbook media keys to control web applications. Specifically, I wanted to use the play/pause and next/prev buttons with MinSub, the HTML5 player for Subsonic.
Pressing a media key doesn’t actually trigger keypress, but pressing F7-F9 does. This means that you need to invert those keys with FunctionFlip or similar, which breaks support for desktop media apps (you would need to push fn+play to control iTunes). I believe some non-mac keyboards will trigger keypress for their media keys.
Lastly, this only works if Chrome is the active window. The whole point of media keys is to let you control music regardless of what software you are currently using.
I ended up using Boris’ more recent implementation, keysocket. This approach uses a small Python app to capture media key events and forward them through a websocket server to the web app. This solves all of the problems with the previous solution, but there are still a couple issues:
Most desktop apps will still take over the media keys, so you need to quit any open media apps.
iTunes gets launched every time play is pressed with no open music app. Of course, this one is mostly Apple’s fault - there really should be an easy way to disable this “feature”. There is a hack that addresses this, but it apparently breaks with code signatures in 10.8.
Both of these are only minor inconveniences, and I’m really happy with this solution. I’ve added it to my fork of MiniSub. I think that these issues could be completely resolved by using the more robust SPMediaKeyTap - maybe I will take a stab at that sometime.
Unity Music Media Keys is also a really solid proprietary solution that works with a variety of music streaming apps.
Getting websites to behave like applications is challenging, and I’m looking forward to seeing what kind of future allowances Google and others will make for web apps that need OS level access.
Photo courtesy of Lifehacker.