Google Music Keyboard Control on OSX

Thanks to  this post and some Applescript hacking, I now have solid keyboard control over Google Music.

The Problem

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
# h/t
# h/t
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
          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 ""
    end if
  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.

7 responses to “Google Music Keyboard Control on OSX

  1. Thanks for the post… Need that since I listen to music at work and need to quickly pause…

  2. Any updates since Play Music went out of Beta? The playPause call in the macWorld post doesn’t seem to work still.

    • Daniel, sorry, but I haven’t updated this in a while. I may move this to an open source repository, and maybe I or some plucky hacker can update it. I’ll add a new comment when that happens.

  3. Hey Guys,
    Firstly thanks for the post – it pointed me in the right direction. I have taken this concept, updated it to use the playback controls on my Mac and made it also compatible with the Hype Machine service.
    You can find my guide here:


  4. Pingback: Google Music & Hype Machine keyboard controls on Mac OSX | Charles Wilkinson

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s