Controlling pandora.com from Alfred 2 and media keys

Written by Alex Wolkov


love

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

Download (PandoraControlsForAlfred.zip)

* 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.
Like-a-charm!

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!

  • Shlomi Asaf

    Thanks for letting me know about this app!

  • altryne

    you welcome! I love it and want to share it with the world

  • chater

    Works great on one mac, but didnt on another. I guess there is a problem in chrome extension. Do u have any suggestions?

  • altryne

    Both of them mnt. lion?
    And is the chrome extension installed on both?

  • chater

    Yes, i’m upgrading second one to 10.8.3.

  • chater

    Didnt help 🙁

  • anonymous

    It worked when I first installed the Alfred workflow and SoundControl extension but now it doesn’t. I installed and uninstalled SoundControl and it still doesn’t work. I also tried the SoundControl extension that is available in the Chrome Web Store. Please help!!!

  • altryne

    Yeah, same here, needed to update the extension, seems like pandora changed something

    Can you try this one and lemme know if it worked?
    http://d.pr/f/lPsT

    If it did, then I’ll update the zip with the new extension

  • anonymous

    That worked! Thanks!!!! This workflow is awesome!!!

  • Deseo Mar

    Pandora appears to have updated their website and some functionality. The plugin does not work anymore for me. 🙁

  • altryne

    can you please try installing this extension, and seeing if it works with pandora directly? (it’s the one I base my alfred integration on)

  • Chris M

    I’ve tried both extensions (now that it’s gone) and the linkage between alfred and Pandora on Chrome is lost. The extension from the Chrome Web Store works *as designed* but just not with Alfred. Are you planning a fix? I really love being able to control Pandora from alfred. Thanks for the effort!

  • altryne

    The author of the original chrome extension had contacted me and asked me to remove his extension from my site :/

  • Chris M

    Yes, sir. I was aware of that and the reasons why. What are the next steps for something that works?

  • altryne

    I’ll try to see if there’s another extension that is open source that I can ride on, if not, I’ll build my own 🙂

  • Justin Gordon

    I’m eagerly awaiting this one as well. Could it work for MOG also? It would be really cool to take the current pandora song and open it up in MOG.

  • altryne

    I have no idea what MOG is 🙂

  • Justin Gordon

    I use both MOG and Pandora. MOG offers the ability to select songs/artists directly, and it offers higher quality than Pandora. It’s worth it!

  • Kyle

    Hi! I’m actually looking to do something similar. Do you have any advice on how to communicate with Chrome? What other options were you considering before selecting your polling approach?