Using Alfred 2 to run Maven scripts

Alfred is a quite popular productivity tool for OSX, however I’ve not cared much for it – until little over a month ago when Alfred 2 was released. The new version’s Power Pack includes a new feature called workflows which caught my attention. This allows you to define a keyword or keyboard shortcut that will run a set of actions of your choice.

I often build from source code using Maven, nearly all of these projects reside in my git folder. So usually it’s a matter of opening a terminal, navigating to the project and executing mvn clean package, then wait for the build to finish. Not a very time consuming process, but with Alfred’s workflow feature it can be improved upon. The Alfred manual is quite limited, so I decided to document the process here to serve as inspiration.

Above is the workflow with two bash scripts and two notifications.

The trick lies in the Script Filter box. It contains a bash script that finds all relevant pom-files and formats the list for use in Alfred. The script is shown below. Note that the expected output is in XML format:

When an item is selected the following script is executed:

The rest is simply a matter of handling the notifications.

Alfred in action

Now when I press Alt+SPACE followed by mvn and a qualifier I’m rewarded with a list of all my root pom-files residing in ~/git. Selecting an entry will execute mvn clean package in the associated folder, a notification will pop up informing me that the script is running. Another notification will be shown when the script is done and if it failed; the error log will be opened.

mvn.png

If you like this workflow you’ll find the file here. It can be easily imported by double clicking on it. Note that the file has been zipped because my crappy service provider is using IIS which thinks files ending with “.alfredworkflow” does not exist.

Leave a Reply