If you haven’t taken a look at Alfred yet, I highly suggest you do (this ESPECIALLY applies to you Quicksilver users). On the surface, Alfred can simply help you find things faster, much like Spotlight on steroids. However, there is SO much more to Alfred than that. One feature that I was recently introduced to and particularly love is Workflows. Using Workflows, you can automate things that were once redundant. The result is a less interruption of what you’re currently working on and thus (hopefully) more productivity.
Think about this scenario: you’re right in the middle of some code block, listening to Spotify and the one song that you absolutely cannot stand comes on. Normally, you’d have to stop what you’re doing, switch to Spotify, change that dreadful song to something else (in some cases ANYTHING else), and then, if you’re lucky enough to not be distracted by Spotify, switch back to what you’re doing and continue coding. I say “lucky enough” because part of the draw of Spotify is music discovery. They want you to be distracted and to peruse their catalog. Don’t get me wrong; this isn’t a bad thing..unless you’re trying to be productive with something that doesn’t include Spotify. Let’s see how using Workflows can remove that distraction and get you back to coding quicker then you can say, “Call Me Maybe" (yes, I went there).
WHAT YOU WILL NEED
Unfortunately, not all of the items needed for this tutorial are free. However, I highly endorse Alfred and paying for the powerpack is so very worth it. To get started, you’ll need the following:
- A licensed copy of Alfred (a.k.a. purchased the Powerpack): £17
- A Macintosh running OSX
- The ability to run Python scripts (for Macs, this should work right out of the box). This tutorial was written using Python 2.x
- The following python modules installed: py_applescript-1.0.0-py2.7.egg and simplejson-3.6.3-py2.7-macosx-10.9-intel.egg
- All of the necessary files can be found at my Git repo, including a completed workflow (for you lazy bastards who want to skip all the fun).
Given that the purpose of this tutorial does not include coding in or installing modules in Python, I’m going to skip those subjects. However, I have provided some contextual links in case you do not currently know how to do these things and would like to learn.
STEP 1: CREATE A WORKFLOW IN ALFRED
Open the Alfred Preferences by either clicking on the sprocket in the search popup or clicking on the menu icon in the top right area of your screen and choosing “Preferences…”. Click on the Workflows icon in the menu bar. You should see something like the following:
At the bottom of the left column, you’ll see a plus icon. Click the plus icon to open a contextual workflow menu. As you can see, there are many options to choose from but we’ll be starting with Blank Workflow, so choose that option. A dialog box will appear which will give you some options for configuring you’re new workflow:
You can configure all of these at a later time if you wish. The only one that is required is Workflow Name so type “Spotify” here and click Create. You will now see your empty workflow listed in the left column. In the screen capture below, it’s also labeled in the upper left corner of the main area as well since it’s the only work flow and thus is active by default:
STEP 2: ADD AN INPUT COMPONENT
Now it’s time to add some muscle to this beast! click the plus icon in the upper right corner to add some functionality. You will notice that clicking this icon shows another context menu, this time showing you the different components available. Since we want Alfred to listen for a specific keyword, let’s choose Inputs > Keyword from the context menu:
You’ll notice that a new dialog box has appeared, this time giving you configuration options for the new input component we are adding. As with the last dialog box, most of this you can configure at a later date. The only value that you must supply is the keyword. I chose “sp” for mine but you can use anything so long as it doesn’t conflict with another workflow. Also, make sure that “with spaces” is checked and that the dropdown menu has “Arguments Required” selected. As we continue you will see why this is important. When you’re done, click Save. The Workflow display has updated to show your input component you just added:
STEP 3: ADD AN ACTION COMPONENT
We now have a work flow that is going to listen for a specific keyword. Unfortunately, it doesn’t know what to do when it hears it so the next step is to add an action component. Click the plus icon in the upper right corner once more, but this time, choose Actions > Run Script from the context menu:
Another dialog box appears, this time giving you the options needed to configure the action component. This component requires a bit more configuring than the last one given what we need it to do. The first thing you’ll want to do is choose the appropriate language interpreter. For this tutorial, we’ll be using python, so in the language dropdown menu, choose the python interpreter option (NOTE: you may have your languages configured slightly differently so for that reason, I’m purposely not including a screen capture or a specific label). For the script that we are going to be using, url escaping should be handled by the script, so you can go ahead and uncheck all of the checkboxes. Finally, add the script in the textarea. For the purposes of this tutorial, the script I am using can be found in the Github repo. When you are done, click the Save button. Your workflow should now include two components and look something like this:
STEP 4: WIRE UP WORKFLOW
There’s one final thing we have to do before we can see this in action; we need to connect the two components. Hover your mouse cursor over the input component. See that little nub jutting out from the side of the input component? Click and drag it towards the action component. As you do, another nub will appear to make the connection. Once the two components are connect as illustrated below, you should be good to go:
STEP 5: IT’S… ALIVE!!
So now it’s time to see if all this work was worth it. First, make sure that Spotify is launched because the script currently does not handle activating the app. Call up Alfred and type “sp artist pennywise” and press return (NOTE: that the icon shown is generic and there is no name shown for the workflow. These are configurations we skipped over but you can go back and customize these ‘til your heart’s content):
If everything was done correctly, you should hear the sonic euphoria of Pennywise. If this isn’t your cup of tea, then you can try out some of the other commands that are available in the default version of this script which are explained in the README in the git repo.
THANKING THOSE WHO MADE THIS POSSIBLE
If you’re familiar with my blog, then you know I like to take a moment at the end of every post to give thanks to those who helped me or inspired me. I’d like to thank Tobias Wennergren for not only showing me how freakin’ awesome Alfred is, but inspiring me to come up with something that has improved my productivity. I hope this post will inspire you to create something just as awesome! Enjoy!