Controlling from Alfred 2 and media keys

Written by Alex Wolkov


A workflow for the new and incredibly awesome Alfred 2, that controls in chrome from Alfred.

Download (

* I was contacted by the creator of soundcontrol extension, and he asked me to remove any links to the modified extension :/

If you want to give it a go, download the Pandora Controls for Alfred 2 archive. Inside you will find both the workflow and the chrome extension to make this happen. (if you don’t know how to install a crx file in chrome , see here)

Download Pandora Controls for Alfred

Available controls : 

  • pplay –    “Play/Pause”
  • ppause – “Pause”
  • pnext –   “Next”
  • pfocus –  Focus the pandora tab
  • pplaylist – Show a list of pandora playlists
  • pplaylist {query} – Filter  pandora playlists, select a playlist to start playing

A little bit on how this is done.

I thought longs and hard how to connect to a chrome extension from Alfred. I came up with a couple of methods. I could make the extension connect to a websocket server somewhere, and wait for commands. That’s fine when I’m building a workflow for myself, but I wanted to share it. And I didn’t want to control the Pandora of everyone who’s using the workflow.

Instead I came up with a “hacky” long polling solution. 

I’ve unpacked the very cool SoundControl chrome extension and inserted a timer function, that fires an Ajax request to a localhost server. Most of the time it fails because theres no server listening on that port.

In Alfred, I’ve wired the workflow to fire up a ruby server, that wakes up, receives a connection sends a control, then dies.

Once the server is up, the extension connects, and receives a control action from Alfred input.

That worked like a charm, the only problem being all those Ajax calls failing. I didn’t want my mac to constantly fire an AJAX call even when I’m just listening to pandora. So I added idle detection to the chrome extension. After 15 seconds, the extension stop firing AJAX calls, and when user is active again, starts again.

That was nice and all, but that only let me to control pandora. And I wanted to go further, and see my playlists list inside Alfred and select from there which playlist I want to play.

In order to do that, the AJAX request has all the playlists info on each request. The “playlist” workflow in Alfred starts another server, which collects the playlists from the request data, and shows them inside Alfred.

Then when the user picks a playlist, the old server starts with the needed “action” for pandora to pick up. Easy right?

Media Keys

While writing this post, I decided to go a small step further and achieve any heavy pandora user dream, wire up a system wide hotkeys to pandora. Preferably even the media keys on keyboards.
This can be easily done with the new (and did I say awesome) Alfred!
I set up 2 hotkeys hooks in Alfred to activate the playpause/next workflows respectively. In my keyboards software, I mapped the media keys to some weird combination I’d never use, like cmd+opt+ctrl+shirt+w and then setup the same hotkey in alfred to activate the respective control.

This whole thing smells a little hacky, but it works and works faboulusly. If you, my dear reader have an Idea how to make this better, don’t hesitate to comment 🙂

Why did I do this?

I gradually fell in love with Alfred, to a point that I now can’t use my macs without it. When version 2 was released, I instantly bought a powerpack license, and went to town!

I really recommend anyone with a mac to atleast download Alfred. And if you do, but the powerpack, it’s so worth it! Only the clipboard history feature is worth those 15GBP for the license, and Alfred has SO MUCH MORE

Disclaimer : I am not affiliated in any way with Alfred. I just love Alfred and love seeing this kind of app succeed.
The team (Ma’ and Pa’ operation, the Pepperrell’s) really listen to their customers, update the software often and are active on twitter and on forums, answering everybody, giving support!