Commands running in our Workflow

Creating a Homebrew Workflow with Alfred on MacOS

One of the first suggestions that I was given when I switched from Windows to Mac was to install and use Alfred, a productivity app for Mac OS X. I have to thank Mason James for the suggestion, as Alfred has been an integral part of my Mac usage ever since. Tomorrow I’ll give an overview of what Alfred is and does, but for now I want to talk about a specific workflow that I made. It’s very simple, but that’s a plus for a starting up tutorial.

Update 11 January 2019: I wrote about a workflow for Homebrew that I started using.

What are we going to create?

The task that we’re setting up is going to be a keyword that will run a series of terminal commands for us. I use Homebrew as a package manager for software on my Mac. This, along with Homebrew Cask allows me to manage most of the software that I use on my computer from the command line.

Similar to an overview of Alfred, I’ll give an overview of Homebrew later, but for now I’ll assume that you can setup both from those sites. Backwards maybe, but I want to show something simple that it can do before walking through setting it up.

So with Alfred I can set keywords that run commands. In this case, I’m going to make a keyword, brew, that when used will run a series of commands to check for updates of installed software, perform those updates, clean up outdated software versions, and check that everything is functioning properly.

We’re going to have eight commands run sequentially, so instead of having to type each of those commands manually and wait for each to run, we can type one keyword, have terminal open for us, and let it run in the background while we continue working.

Let’s get started

1. Create a new Workflow.

Open Alfred Preferences, and navigate to the Workflows screen. In the lower left of the screen click the plus button to create a new Workflow. To save time, go to Templates > Essentials > Keyword to Terminal Command, and select that template. Give a name and description to your workflow, and add an icon if you want.

Setting up a template Workflow
Starting with a template for our Workflow
Adding details to the Workflow
Setting the details of our Workflow

2. Set the options and commands for your Workflow.

The two nodes of the workflow
The two nodes of our Workflow

When you create the Workflow you’ll have two nodes to work with: the keyword, and the terminal command. Double click on the keyword box to pull up the options for the keyword. We’re going to set brew as our keyword, and change to no argument since we aren’t adding any other commands. If we wanted to we could say setup an argument to update brew, cask, or both, but I just do both by default. I add a title and icon to display when I run the command and click save.

Setting a keyword for the Workflow
Setting the keyword options for our Workflow

Next, double click on the terminal command node. This is where we’re going to put the commands that are going to run after the terminal is opened. The below commands are what I have setup for my Workflow.

brew update
brew upgrade
brew cask upgrade
brew cleanup
brew cask cleanup
brew prune
brew doctor
brew cask doctor

The above updates Homebrew and Cask, then upgrades software that is currently installed and out of date for both. Next we use cleanup to uninstall older versions of the apps that have been updated. Prune will cleanup any outdated symlinks, and doctor will display any notes for potential problems that we can review.

Add terminal commands to the Workflow
Adding terminal commands to our Workflow

Let’s save this series of commands and give it a go!

3. Try running the command.

To use this command we need to type our keyword into the Alfred menu. Use whatever hotkeys that you have set to open Alfred (the default is option+space). When you start typing the brew keyword you’ll see the workflow appear as an option. Click enter when it’s selected to run the command.

Running our Workflow with a keyword
Typing our keyword pulls up our Workflow

If everything is setup properly your terminal application should open and paste in the series of commands. Since each is on a separate line they will run sequentially. You can see the commands as they run and any output they have. Since I ran this command shortly before taking screenshots for this tutorial everything is already up to date for me except for a bit of cleanup.

Commands running in our Workflow
Running the Workflow opens terminal and runs our commands

Awesome! This saves a bunch of time!

This Workflow saves me a bunch of time by updating applications in the background without having to wait for me to open them and have each application run their own update check. Since I’m opening an app when I want to use it the need to update can interrupt my workflow.

The benefits of this system include:

  • All applications stay up to date with new features and bug fixes
  • I don’t have to wait until I want to use an app to update
  • I won’t click ignore on an update and forget to do it later
  • I can make sure that my computer stays clean with outdated versions of applications getting removed for me
  • I don’t have to remember all of the commands to run, what order to run them in, or have to wait for each one to run before typing the next one

If you use Homebrew already, I’d suggest setting something like this up to make it easier to manage. It only took me a few minutes to setup, takes a second to run whenever I have time to update (generally every morning for me), and provides the kind of background benefits that save a bunch of headaches over the long term.


Posted

in

, ,

REPUBLISHING TERMS

You may republish this article online or in print under our Creative Commons license. You may not edit or shorten the text, you must attribute the article to david wolfpaw and you must include the author’s name in your republication.

If you have any questions, please email david@david.garden

License

Creative Commons License AttributionCreative Commons Attribution
Creating a Homebrew Workflow with Alfred on MacOS