Alfred2 Workflow for Controlling Concentrate

Back in march I wrote about how I fought procrastination with my hosts file hack. I have since then abandonned this practice, but bad habits die slowly - and I sometimes need to educate myself a bit. I have had a license for the Concentrate app for years now - and I decided to use that this time around.

As always I managed to start procrastining by coding. Today because I needed - or at least decided I needed - a way to start/stop specific tasks (activities in Concentrate terms) with the help of Alfred.

The solution was three fold. First i needed to get the activities from concentrate (to ensure the list not be hardcoded), I needed a way to filter the list of available tasks from alfred, and finally I needed to start/stop concentrate from alfred with the given activity name.

Ready? Get the activities

This first part proved to be quite easy. Concentrate has a AppleScript dictionary, which includes getting all the activities as a list. I decided to write a very short AppleScript, to just output these values.

Set? Filter the activities

I decided to write the filtering in ruby. Again, there is three parts. Get the list from the applescript, parse the list into an array, output the xml alfred expects.

The first two steps was done with “one line” of ruby.

The last part was done with two lines of ruby - ensuring that the search for activities was done case-insensitively.

Concentrate!

Finally the autocompleted query is sent through another AppleScript which is used to start (or stop) an activity.

The complete source is on github. The repo also contains the compiled workflow ready for install.