Thanks to this post and some Applescript hacking, I now have solid keyboard control over Google Music.
Google Music is very nice. One thing I need though, is to be able to quickly pause the music, or just show the running browser tab as quickly as possible. In iTunes these aren’t a problem because iTunes keyboard shortcuts already exist, and iTunes is its own application, whereas Google Music is one of possibly dozens of browser tabs in Google Chrome.
The Start of the Solution
To start, the post I refer to shows how to use OSX Automator to set up control Google Music. It gives examples for a play/pause toggle, and describes the very simple delta from that and “next track”, “previous track” and “toggle shuffle”. Toggling shuffle doesn’t mean much to me, but whatever.
The difference between a generic keyboard and programmable keyboard
Then the post goes on to describe how to bind those commands to keystrokes. Here’s how it does it. Automator lets you create all sorts of tasks: one of them is called a Service, which you can then bind to keyboard shortcuts using System Preferences > Keyboard > Keyboard Shortcuts.
Very nice! However, since I have a programmable Logitech keyboard I actually would prefer to bind the actions to more interesting buttons. (I could see, for instance, replacing the keyboard’s play/pause button, but other keys will do since I still use iTunes. However, if you don’t use iTunes, then replacing those buttons is a cinch.)
Services can’t be controlled via the Logitech Control Center, so the solution was to make Automator Applications instead of Services. Automator Applications work just like regular applications, and are easy to bind to the Logitech Control Center. If you aren’t using a programmable keyboard then you would do just as well to create Services instead of Applications.
Additional Feature: Open Google Music
The automator tasks were nice, but I also wanted the Google Music tab to appear in the foreground. It looks for any Google Music tab, makes it the active tab for the window, and moves the window to the front, so it’s in your face. As a bonus, it starts Google Music if it isn’t running in any browser tab. After some Applescript hunting, here’s what I came up with.
# h/t http://hints.macworld.com/article.php?story=20110622061755509 # h/t http://superuser.com/questions/263198/switch-between-google-chrome-tabs-using-applescript # h/t http://saikotroid.blogspot.com/2010/12/open-new-tab-with-applescript-in-chrome.html on run tell application "Google Chrome" set found to false set allWins to every window repeat with currWin in allWins set allTabs to every tab of currWin set i to 0 repeat with currTab in allTabs set i to i + 1 try if ((characters -10 thru -1 of (title of currTab as string)) as string) = "Music Beta" then set (active tab index of (currWin)) to i # tell window currWin to activate set the index of currWin to 1 set found to true end if end try end repeat end repeat if (found = false) then set myTab to make new tab at end of tabs of window 1 set URL of myTab to "http://google.com/music" end if activate end tell end run
It took me a couple of hours to figure all this out, but most of that was trying to figure out how Applescript worked.
Google Music is already somewhat keyboard friendly, so, for instance, navigating between tracks for a playlist or album can be controlled with the arrow keys. There’s a lot to play with when it comes to Automator; and I’ll probably play with it fairly soon.