Alfred: Not Just For Batman

jakewca

Jake

Posted on August 20, 2019

Alfred: Not Just For Batman

Summary: Alfred is a neat macOS app at first but crazy powerful once you understand it.

Alfred: Not Just For Batman

Sometimes the hardest part about getting work done isn’t the challenging bits. It’s the boring parts. You know the ones. Writing up a pull request, or navigating to tickets, etc. Sometimes it’s hard to get rid of these things. If you can, that’s great. If you can’t, there’s Alfred.

After using Shortcuts on iOS and discovering my new love of making workflows to automate my busy work, I decided to have a search for a comparable tool for macOS. Automator on macOS is an excellent start but lacks the ease of use of Shortcuts. For years I was convinced that Alfred was a moderately improved Spotlight search and therefore not worth the money.

🤵First Servings

After installing Alfred and starting to configure it, I knew that I was wrong. Where Spotlight does a decent job of searching files, Alfred is a tool for performing actions of many different types, one of which happens to be an ultra-fast search for files. Alfred is highly configurable and going through its exhausting preference panel helps tell you something about the number of actions available.

Here are some of my favourites. These are built-in by default, and I use them almost daily:

Clipboard History: If you’ve ever had to deal with copy-and-pasting two things at once, this solves that problem elegantly. After typing in the keyword (default of clipboard, I switched mine to pb), or pressing the keyboard shortcut (Alt + Command + C), you get a list of the most recent things you’ve copied. Command + 3 pastes the second most recently copied. Alfred is even smart enough not to store passwords from 1Password or Keychain in the clipboard history.

Snippets: The reason that Command + 3 returns your second copy is because of snippets. They’re the first result. If you’ve ever had to copy and paste a template before filling out the specific details, you know how annoying it is to do it again. Snippets are the solution to that. You can paste the template into a snippet and then use the keyword snip to search for it. An example of this would be using “Merge Request” templates. I can open Alfred Command + Space and then type snip merge and press enter. The field populates.

Web Search: By default, Alfred has searches for many popular websites setup. You can easily search IMDb Avengers to find out more about the Avengers movie. Where this gets really good is that you can add your own custom searches. For example, I have my work Wiki setup using wiki issue login fails on error to search for any issues containing that text. You can make this even more powerful, but we’ll get into that below.

Want to add a new web search? Just go to the site you want to search, type in {query} and do a search. Replace the part of the URL on the results page that says %7Bquery%7D with {query} and then add the URL as a new entry to the table of searches. Here’s an example where I added in a Python search in about a minute:

Alfred: Not Just For Batman
The query and title added in for a py keyword to search Python documentation.

If you have or plan to add your own search, what will it be for? Comment at the bottom. I’d love to hear about it!

Web Bookmarks: Similar to Web Search, Alfred can search for and open your bookmarks. Even better than that, it can open them in the browser in which the bookmark exists. If you deal with terrible intranet sites that should have been purged a decade ago, this is amazing. A quick search for (or if you have it set, a keyword followed by) þe olde SVN opens an instance of Chrome when one is warranted. Unfortunately, the bookmark search only works in Safari and Chrome. You can have pages open using Firefox, but we’ll get into that below. (Is the suspense killing you yet?)

The Rest: Calculator, Dictionary and Contacts are all improved over Spotlight. Alfred also includes actions for controlling iTunes, the entire macOS system and even the ability to run terminal (Terminal.app, iTerm or Hyper, theoretically more) commands directly, opening a new window with the result. Pretty neat, eh? Let’s get to the cool part though: Workflows.

If you have used Alfred before, what was your favourite feature? Was it one of the ones I listed or something I may have missed? Comment at the bottom. I want to hear from you!

🏗 Workflows

Everything up to this point has been pretty neat. Workflows, though, take this app from nice-to-have to productivity-enhancing-drug. Workflows, as the name implies, are a way of performing one or more actions as easily as possible.

There are five parts: Triggers, Inputs, Actions, Utilities and Outputs. Triggers and Inputs start a workflow before handing off to Actions or Utilities (which may also trigger other Actions or Utilities), finally ending in an optional Output.

It seems simple enough. So why all of the fuss? All five of these parts offer a lot of different options.

🚦 Triggers can be hotkeys, other Alfred features, or an external trigger (which generally means using AppleScript. Expect more on that in another article!). Think hitting Command + Alt + V or running a Bash command. These don’t even need to be you running the trigger, either. You can use tools like fswatch to run it whenever a file is updated.

⛽️ Inputs are keyword-based actions that may have a query. Use these when you’re trying to use Alfred similar to Spotlight. “Keyword” works for simple actions like typing in keyword [query...]. For example, I have one set up so git jakew/dotfiles opens github.com/jakew/dotfiles, which makes getting to the project on Github super easy.

Another significant option for Inputs is a Script Filter. This one allows you to run a script and return the results directly in the Alfred window. It can run Python, PHP, Ruby, Perl, AppleScript or even just a Bash function. Returning JSON or XML in the proper format allows Alfred to show a custom list of results. For example, I have a Python wrapper that returns all of the tickets I own in my organization's issue tracker. By typing issues, the list is populated and selecting an option opens the issue in my browser. (Unfortunately, my issue workflow uses proprietary software so I can’t release it. 😫 Just know that it would have blown your mind.)

🏃‍♀️ Actions are generally the doing part of the workflow. For example, they might open a specific app, file or URL, or run a system command. An Action can also run an AppleScript script for automation purposes. You can combine it with applications that use x-callback-urls as well (which is itself a topic for another article.)

🧰 Utilities are the logic of the workflow. If query is this, then do that. Split arguments. Convert X to Y. Stuff like that. One extra utility available is “Debug,” which shows you the current values in your workflow objects.

📺 Lastly, Outputs are how you get the content or notification out of the workflow. It can be as simple as a macOS Notification or sound, or it can itself trigger a key combination. Outputs may also write text where your cursor is currently waiting, or put its result in your clipboard, ready for you to paste. To get even crazier: an output may also call an “External Trigger”! Remember when we mentioned those above? Yea, you can have workflows calling workflows. 😱

❤️ Sharing is Caring; Sharing Automation is Doubly So.

“Okay, you’ve convinced me,” you might be thinking, “but do I want to sit down and make all of these workflows?” The simple answer is: you don’t need to. A large community of people are already making a lot of them and are eager to share! You can join in on the Alfred Forum and even share the workflows you’ve made.

You can also get workflows from the Alfred Blog or even in future articles on Effective Dev. Here is an example of one I’ve already made:

  • Paste as Code Block: When “pasted,” the contents of your clipboard paste with three grave-accents ( ````` ) surrounding them to create a code block. Pasting like this is helpful in Markdown on Github/Gitlab, and in Slack.

If this article has convinced you to get Alfred or if you already have it, and you have made some workflows of your own that you’d like to share, I’d love to see them in the comments below.

🏁 Conclusion

Alfred has been amazing for increasing my productivity. As long as I don't spend my entire day making workflows instead of doing work. Alfred can get many things done, so you don’t have to. Its community is vibrant and offers a ton of resources that you should check out. Of course, your workflows are your own, so dig in and give it a try.

💖 💪 🙅 🚩
jakewca
Jake

Posted on August 20, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related