Use AppleScript to control Google Play Music All Access

Thanks to the Create global hotkeys to control Google Music playback post from June 23, 2011, I figured out how to control Google Play Music All Access via AppleScript. This is useful because I have a Griffin PowerMate which can be configured to launch AppleScript commands. Now I can pause/play music and skip to previous/next track my pushing or rotating the PowerMate. I had previously done this for the Mog OS X application and I wasn’t willing to switch to Google Play Music All Access because of the lack of global keyboard bindings. Now I have them.

The following are adaptations of the script posted on Create global hotkeys to control Google Music playback but I’ve updated them to be a little more fault tolerant and to work with the latest Google Play Music All Access.

tell application "Google Chrome"
  repeat with w in (every window)
    repeat with t in (every tab whose URL contains "play.google.com/music") of w
      # Options for action are:
      # rewind
      # play-pause
      # forward
      set action to "play-pause"
      tell t to execute javascript "document.querySelector(\"[data-id='" & action & "']\").click();"
      return
    end repeat
  end repeat
end tell

If you want to get this as an Alfred App Workflow, download it here.

comments powered by Disqus