Friday, February 20, 2015

Keyboard shortcuts for Pandora One, iTunes, and Amazon Music

Below is a script that I have been using successfully for months on Windows 7 that controls play, pause and volume from keyboard shortcuts. It relies on AutoHotKey. All three music players work exactly the same way with the same set of keyboard shortcuts so they quickly become second nature. Only one music player should be running at a time.

I got this script from here and then modified it to work with iTunes and Amazon Music.

; This script exposes control of the pandora app to external keypresses
; It is a modified version of the script found on Chris DeLashmutt's blog,
; "Grog's Blog" - http://groggluebutt.blogspot.com/2009/02/official-pandora-desktop-and-hotkey.html
;
; His version of the script failed to work with Pandora One 2.0.0, with a few simple modifications
; I was able to get it to work.  The script should be able to modified easily to change the hotkeys
; to anything that is desired, for more information check out the documentation at http://www.autohotkey.com/
;
;
; Ctrl-Win-Alt-Right Arrow (or Next Media Key), Skip song
; Ctrl-Win-Alt-Up Arrow, Volume Up
; Ctrl-Win-Alt-Down Arrow, Volume Down
; Ctrl-Win-Alt-Space (or Play/Pause Media Key), Pause/Resume Playing
; Ctrl-Win-Alt-Plus (or + on Numeric Keypad), Thumbs up a song
; Ctrl-Win-Alt-Minus (or - on Numeric Keypad), Thumbs down a song
; Ctrl-Win-Alt-O, Activates and Pandora application window if minimized
; Ctrl-Win-Alt-M, Minimize the Pandora application window
; Ctrl-Win-Alt-X, Closes Pandora
; 
; Any future updates can be found at http://notunusual.net/pandoraone_autohotkey/
;
; Revision History
; Version 1.4 10/29/2012 - Added media key support for play/pause and skip/next track.
; Version 1.3.1 5/23/2012 - Fixed a strange issue where if you minimized, then restored the window through the 
;        script the window would be visible, but wasn't gaining focus so you couldn't interact with it
; Version 1.3 5/1/2012 - Added the ability to active and minimize the pandora window, made the close command actually close pandora
; Version 1.2.1 10/16/2011 - Fixed an issue where commands were being sent to any open Adobe AIR window, not just Pandora One
; Version 1.2 12/9/2010 - Added a hot key to shutdown pandora
; Version 1.1 - Added the ability to have the script work if the window is minimized/hidden thanks to Jeremy Hurwitz for sending me this tip

; Make the script work even if the window is hidden
DetectHiddenWindows, on

; Only allow a single instance of the script
#SingleInstance


; get the window title

DoesPandoraExist()
{
 IfWinExist, Pandora
 {
  IfWinExist, ahk_class ApolloRuntimeContentWindow
  {
   return true
  }
 }
 return false

}

DoesITunesExist()
{
 IfWinExist, ahk_class iTunes
 {
  return true
 }
 return false

}

DoesAmazonExist()
{
 IfWinExist, ahk_class Amazon Music
 {
  return true
 }
 return false

}

; Ctrl-Win-Alt-Right Arrow, Skip song
Media_Next::
^#!Right::
If DoesPandoraExist()
{
 ControlSend, , {RIGHT} ; Next
}
If DoesITunesExist()
{
 ControlSend, , ^{RIGHT}  ; > next
}
If DoesAmazonExist()
{
 ControlSend, , ^{RIGHT}  ; > next
}
return

; Ctrl-Win-Alt-Up Arrow, Volume Up
^#!Up::
If DoesPandoraExist()
{
 ControlSend, , {UP} ; VolUp
}
If DoesITunesExist()
{
 ControlSend, , ^{UP}  ; vol up
}
If DoesAmazonExist()
{
 ControlSend, , ^{UP}  ; vol up
}
return

; Ctrl-Win-Alt-Down Arrow, Volume Down
^#!Down::
If DoesPandoraExist()
{
 ControlSend, , {DOWN} ; VolDown
}
If DoesITunesExist()
{
 ControlSend, , ^{DOWN}  ; vol down
}
If DoesAmazonExist()
{
 ControlSend, , ^{DOWN}  ; vol down
}
return

; Ctrl-Win-Alt-Space, Pause/Resume Playing
Media_Play_Pause::
^#!Space::
If DoesPandoraExist()
{
 ControlSend, , {SPACE} ; PlayToggle
}
If DoesITunesExist()
{
 ControlSend, , {SPACE}  ; play/pause toggle
}
If DoesAmazonExist()
{
 ControlSend, , {SPACE}  ; play/pause toggle
}
return

; Ctrl-Win-Alt-Plus, Thumbs up a song
^#!NumpadAdd::
^#!+::
If DoesPandoraExist()
{
 ControlSend, ahk_parent, {NumpadAdd} ; ThumbsUp
}
return

; Ctrl-Win-Alt-Minus, Thumbs down a song
^#!NumpadSub::
^#!-::
If DoesPandoraExist()
{
 ControlSend, , - ; ThumbsDown
}
return

; Ctrl-Win-Alt-X, Closes the window
^#!X::
IfWinExist, Pandora
{
 WinKill ; Close Window
}
return

; Ctrl-Win-Alt-O, Activate the window
^#!O::
If DoesPandoraExist()
{
 WinShow   ; Show the window
 WinActivate  ; Activate Window
}
return

; Ctrl-Win-Alt-M, Minimize the window
^#!M::
If DoesPandoraExist()
{
 WinHide  ; Hide instead of minimize Window, it does somethign strange if we activate it after minimizing it
}
return

1 comment:

  1. Thank you! This is a helpful script -- and saved me the time of having to write one myself. It has always bugged me that the Pandora One app does not support media keys.

    Here's a caveat for others who use Chrome as their web browser: Depending on which extensions you have installed, Chrome will hijack your media keys (i.e. the input will be sent to Chrome instead of other applications, even if Chrome is minimized). Fortunately, it is not difficult to change the settings in Chrome so that Chrome only gets media key input when a given extension (e.g. Google Play Music) is actually active.

    Open the Chrome app menu
    Menu (three lines) --> More Tools > Extensions
    Click ‘Keyboard Shortcuts’ at the bottom of the page
    Change the media key options listed for Google Music from ‘Global’ to ‘In Chrome’
    Do this for any other extensions that have 'Global' listed for the media keys.

    I hope that helps others.


    ReplyDelete