Using Alfred to setup your dev environment

trigger

This started as a post about all the ways you could use Alfred outside of just launching apps, but the post quickly became a book in size, so I decided to split it into a series. To prevent the series from becoming the only content on my blog, I’ll focus on the use-cases that are specific to my everyday workflow.

I constantly think about ways to improve my workflow. The main goal is to automate any menial tasks, so I can focus on the more important ones. One of the biggest lesson I’ve learned since starting my own business is that the value of time cannot be measured, and anything that saves time is well-worth the initial time invested.

I started analyzing my typical day-to-day. Are there any repetitive tasks soaking up my time? The first that came to mind was setting up my dev environment. With TeuxDeux, I need several Terminal tabs for the following processes:

  • rake server runs the web server, which serves the app and javascript tests.

  • rake guard cleans all public folders and auto-compiles all HAML, SASS, and Coffeescript files.

  • bundle exec autotest watches Ruby source folders and runs Ruby unit tests with RSpec.

  • bundle exec racksh enters the app’s console.

Sure, each process requires only a single-line command, but tally how long it takes each and every morning and you can see the effect. Aside from lost time, it’s a daily hurdle that must be done before I’m able to do any work, and it’s a task that requires no skills, unless you type it one-handed—that takes skills. Wouldn’t it be nice if this could all be done with a single command? Yes, that would be quite nice.

Luckily, Alfred gives its users the ability to write extensions—all sorts of extensions! For my case, I need to write an Applescript extension, so I click the ’+’ button in the bottom left of the Extensions tab in Preferences and select ‘Applescript.’

extensions

I set the title AND the icon because this is an extension I’ll see everyday and anything with an icon is legit.

new

From there, I describe the extension, set its keyword (something easy), and write the Applescript.

new

Applescript isn’t your everyday programming language, so I had to dig to find the correct syntax. The code starts by launching Terminal if it’s not already open or bringing it to the front if it is. I specify the commands I want for each tab and the script loops through them, opening a new tab for each one.

tell application "Terminal"
  activate
  set command_list to {"rake server", "rake guard", "bundle exec autotest", "bundle exec racksh", "subl ."}

  repeat with the_command in command_list
    tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
    do script with command "cd ~/projects/teuxdeux;" & the_command in selected tab of the front window
  end repeat
end tell

That’s all. By setting aside 10 minutes one morning, I can now start writing code sooner and get to what really matters. That makes think—what else could I do in a short period of time to greatly improve my workflow? The posts to follow will continue this discussion. If you have tricks of your own, feel free to share them in the comments.