PowerShell Hotkey to Pause Pandora

I’ve got a neat application that I use to map keystrokes to background PowerShell functions / script blocks. I recently started using Pandora more often, and the killer problem is when somebody drops by the office to ask a quick question. You dig around all of your open Explorer windows until you find the one for Pandora, then find the Pause button.

Here’s a function that does all of that for you, and maps it to Control+Alt+P:

001
002
003
004
005
006
007
008
009
010
011
012
013
function PausePandora
{
    $ie = New-Object -Com Shell.Application
    $pandora = $ie.Windows() | ? { $_.LocationName -like "*Pandora Radio*" }
    if($pandora)
    {
        $pandora.Navigate2("http://www.pandora.com/#/paused")
    }
    $ie = $null
}

## Pause Pandora
$keyMapping['Control,Alt,P'] = @{ Action =  { PausePandora } }

3 Responses to “PowerShell Hotkey to Pause Pandora”

  1. ksariash writes:

    if you want your hotkey to play/pause, change your navigate url to…

    javascript:p=(document.location.href.match('paused'))?false:true;Pandora.pauseMusic(p)

  2. Janssen Jones writes:

    For some reason I couldn’t get this to work. It would actually change the URL in my Nav bar to http://www.pandora.com/#/paused, but the music would keep playing. I see that clicking the pause button on the music goes to this URL, and the music actually pauses, but running the Navigate command from PoSh just changes the address bar without stopping the music. I didn’t devote much time to troubleshooting. Was just wanting to see if the function worked.

  3. Janssen Jones writes:

    Update: Never mind, it’s now working. Not sure what changed. I opened up an elevated PowerShell prompt and re-ran the function to see if it was UAC related, and the music actually stopped. Then I tried the original non-elevated window and it worked as well. Now I can’t get it to fail. 🙂 Not sure what actually happened… Oh well, it works! Very cool snippet!

Leave a Reply