Ever since I switched from iTunes to using web-based music players (Google Music, Amazon Cloud Player, and Pandora), I've wanted the ability to control them with global keyboard shortcuts. The other day, I finally took the time to set it up, and I'm very happy with the results:
If you're interested in setting this up for yourself (or simply learning about how it works), download the project files here, then follow these instructions:
- Unzip the project files. You should see a directory called "music_control".
- Make sure you have node.js installed, then cd into the "music_control" directory and start the server with:
node server.js. - Cd into the "extension" directory and open "background.html" in your favorite editor. Change the
SERVER_HOSTvariable to reflect your host name. - In Chrome, go to Window > Extensions. Make sure "Developer Mode" is checked.
- Click on "Load unpacked extension," then navigate to the "extension" directory. (You can also package the extension and install it normally by double-clicking on the resulting "music_control.crx" file.)
- Install any application that lets you map global keyboard shortcuts to shell scripts (or AppleScripts, but I prefer bash). I used an app called Shortcuts, but I'm sure there are plenty of free alternatives.
- Setup whatever keyboard shortcuts you want to map to the following bash commands (note that you can use something like
wgetrather thancurlif you prefer):curl "http://localhost:8000/music?play"curl "http://localhost:8000/music?next"curl "http://localhost:8000/music?previous"
- You're done! You should now be able to control you web-based music players with keyboard shortcuts.
I realize there are a lot of moving parts here, and any number of ways to accomplish the same thing. If you decide you don't want to use this exact implementation, hopefully this will at least get you started down the right path of your own setup. Let me know if you get this working and/or if you adapt the concept to something equally or even more interesting. I have lots of ideas for where this could go.









I've been tempted to set this up with Autohotkey for a while, but just haven't bothered yet. Of course, sadly, autohotkey is windows-only.
Posted by: Alan | June 20, 2012 at 12:03 PM
Hi Christian
I'm looking to implement a similar feature for a web app I'm building.
Have you made any more progress or have any recommendations how I would implement this so it would work for my users and my custom player?
Would this be easier if I was running this completely custom just for 1 web app and running my own node server on ec2?
Thanks again for the work and open sourcing this!
Posted by: Mr. K | March 25, 2013 at 03:09 AM
Running node on an instance of EC2 is definitely a good start, but you still have to have a method of capturing keystrokes which means running a local native application. Have you figured that part out yet?
Posted by: Christian Cantrell | March 25, 2013 at 06:23 AM