PowerShell Hotkey to Pause Pandora
Friday, 26 February 2010
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 |


Subscribe to this blog.
No. 1 — November 29th, 1999 at 5:00 pm
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)No. 2 — February 26th, 2010 at 6:29 pm
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.
No. 3 — February 26th, 2010 at 6:35 pm
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!