Global Google Music Shortcuts
I like listening to music while I code. My favorite music subscription thingy lately is [Google Play Music](music.google.com). It has a great selection and its radio feature doesn’t seem to be as affected by Pandora’s Law, which is:
The natural phenomenon that occurs whenever a generated radio station plays for more than an hour, leading to strange, unlikable songs and an inevitable ‘WTF is this?’ moment on the part of the listener.
The other day I was working on an awesome prototype with d3 and was totally in the zone (if you don’t know what the zone is, it’s ok. Muggles are welcome here too). Suddenly I found myself listening to some Selena Gomez song (no offense, she’s perfect in every way) that made me want to hurt a puppy. So I searched frantically through what seemed like a hundred open tabs in Chrome, finally finding the right one and hitting option -
to end my misery with a thumbs down. The zone was gone. Selena threw off my groove. So, naturally, I spent the rest of the afternoon figuring out how to make global keyboard shortcuts for Google Music. I’m really glad I did. Music should boost your productivity, not detract from it. Now a thumbs down, thumbs up, next song, play/pause etc. is just a keystroke away, whether I’m focused in Chrome or not. Here’s what I have so far, feel free to try it out and give feedback.
Step One
Install Fluid. It’s a simple app that lets you create a “desktop” app out of any URL. Once installed, enter “Google Music” for the name, https://play.google.com/music/listen
for the URL, and give it a better icon by saving and selecting this image. Doing this will give you a dedicated app for Google Music, which is convenient and also makes scripting easier.
Step Two
From here you can use AppleScript to do whatever you want. I find it’s easiest to just emulate the hotkey for Google Music’s built in shortcuts. For example to switch to your Google Music “app”, hit play/pause, and hide the app, the script is simply this:
tell application "Google Music" to activate
tell application "System Events"
tell process "Google Music" to keystroke space
delay .1
set visible of process "Google Music" to false
end tell
This quickly focuses the music app, makes it play or pause, and hides it again in the background.
Step Three
Wire up the running of your applescript with a keyboard shortcut. For this you can use either Alfred workflows or Keyboard Maestro or whatever you like. I use ctrl option cmd + [key]
for my shortcuts. So to skip forward a song it’s ctrl option cmd + right arrow
.
Step Four
Make one of these scripts for every shortcut you want to run, the only difference being the keystrokes you emulate. If I wasn’t lazy I’d probably put the common code into a function and pass it the keystroke parameter.
There you have it. Global keyboard shortcuts for Google Music or any other web app.
UPDATE: I realized that Google Music will un-thumbs-up a song if it already has a thumbs up. That’s no good, I want to be able to thumbs up a song without first checking to see if I’ve already given it a thumbs up. So I use Keyboard Maestro to check for the existence of the grey thumbs up button, and conditionally execute the keystroke. Works like a charm. Here’s a screenshot of my macro: