Advertisement

Alfred Workflows for Beginners

by
This post is part of a series called Mac for Beginners.
Evernote for Beginners: The Basics of the Most Popular Notebook App
iMovie: An Introduction

Ever since Alfred 2.0 was in beta, I have been making Alfred workflows for myself and for others. It is a lot of fun and very helpful to my daily workflow. I usually average using Alfred around 130 times a day, with my peak day of 768 times. I am going to show you the basic concepts of workflow design in this tutorial, all the way to the very advanced features that you can use in your own workflows in later tutorials. So, come join the fun!

If you just installed Alfred and you have not used it yet, please read the great introductory tutorials, Up and Running With the Alfred Powerpack - The Basics, and Up and Running With the Alfred Powerpack - Workflows, on Tuts+. I will mostly assume that you understand what is contained in these articles. I might cover a few things again, but just enough for clarity.

Alfred is a free program for just the launching and searching abilities. But, in order to write workflows, you will have to purchase a Powerpack license. With a Powerpack license, you can use workflows, change your themes, syncing, and have access to statics about your usage of Alfred. It is well worth the expense.


How to Create Workflows

When you activate Alfred by your hotkey that is set (default is Command Space), you will have what is referred to as the Alfred prompt.

Alfred Prompt

Alfred Prompt

In the upper right hand corner of the Alfred prompt is a little gear icon. That icon is how you bring up Alfred Preferences program. It is a separate program from Alfred, but interacts with Alfred in such a way that you would think they were the same program. When you make a workflow or change a preference in Alfred Preferences, it is immediately available in Alfred.

With Alfred Preferences open, you will notice the top toolbar has an entry called Workflows. It is in this screen that new workflows can be created, edit existing workflows, or simply play around with Alfred. I have a workflow I named Test just to test on different concepts in workflow design.

For this lessons, I will be creating a workflow to do all of the work for this tutorial. It will be easier to study the concepts and get familiar with how things work if it is not necessary to change workflows all the time. So, a grab bag of functionality in a workflow will work for us.

Therefore, create a new workflow and give it the name MacTuts:Alfred Workflows - Beginner, a description of A test workflow for learning how to make workflows, you can use your name and web site for those areas, and an id of com.tuts.mac.AlfredWorkflowBeginner. The id of a workflow is very important, especially for more advanced workflows that will be using caching and data storage. I will explain those concepts in the advanced workflow tutorial.

Creating the Workflow
Creating the Workflow

In order to look nice, it should have an icon. Get the image from the download and drag it to the icon box. Now, every block that you can set an image in will use this image as the default image. For example, the keyword block takes an optional image. If you leave it blank, it will use this image as the default.

When you click on the Readme tab at the top, you will be given a nice place to tell users how to use your workflow. I try to always document my workflows because I might come back to it in several months and not remember what that workflow does. It is a good practice to always keep this description of your workflow up to date.

Workflow Readme
Workflow Readme

With all the information in place, press the Create button and you will have the workflow. I like to think of this area as a drawing board for working on a workflow.

A Bare Workflow
A Bare Workflow

To add actions to the workflow, you simply choose out blocks from the + icon in the upper right hand corner and interconnect them as you need. Building a workflow is similar to playing connect the dots with different blocks that perform the actions needed.

Add Actions Menu
Add Actions Menu

Theme of Your Workflow

Now that you have a blank workflow, let’s give some thought to what that workflow is suppose to do. A good workflow development demands that you keep one workflow about a single topic.

For example, you should not create a workflow My Hotkeys and have a keyword activation block. That workflow should just contain hot key definitions. Or, create a workflow to work with the Google search engine that hooks to Duck-Duck-Go! That just makes for confusion.

Each workflow should have a general theme and you should stick to it. That makes finding a sub-function of a workflow easier to find. I have over 80 workflows in my Alfred. If I wanted to see how the gist lister works for GitHub, I will simply go to the GitHub workflow and look there for that function. This is logical and very convenient.

Saying that, I have already muddied that rule in this workflow. You are going to have one workflow with the theme of learning how to make workflows. Therefore, it will have many, unconnected functions. But, they do have the general theme of learning how to make a workflow.


Organization of Your Workflow

When you are placing your blocks and routes, it is best to keep it clean. That way you and others can clearly see what you are doing. For example, this workflow layout has connectors that cross over each other. This makes it very hard to figure out what block is connected to which block.

Messy Workflow
Messy Workflow

It just takes a little thought and work to keep everything as neat as possible.

Clean Workflow
Clean Workflow

Also, I try to group logical blocks close to each other. For example, I created a workflow to contain all of the special actions that I use with one company. It contains shortcuts to websites, special text expanders with calculated results, etc. All of the actions that are the same (shortcuts next to other shortcuts, text expanders with other text expanders, etc), I group together so that they are easily identifiable.

The goal with good workflow organization is to make everything as readable as possible.


Exporting Your Workflow

In the lower left corner, you will notice the Share button. That button brings up a single menu item named Export Workflow… You use this to save your workflow in a format that you can then email to someone else and they can load it in to their Alfred.

Exporting Workflows
Exporting Workflows

It defaults to using the name of: <workflow name>.alfredworkflow. It is really a zip file containing everything about that workflow. If you change the .alfredworkflow extension to .zip, you can then unzip it and see how a workflow is made. It is mostly a plist file, icon file, and anything else you add to your workflow to use. I will be explaining this more in the advance tutorial.

Since you have such a convenient way to share workflows, it just makes sense to send it to people or post it on the net. I share my workflows on Alfred Forums, my personal website Custom Computer Tools, my GitHub OctoPress site, and on my GitHub account. Really, all of those locations ultimately link to the workflows on my GitHub account.

If you need a workflow, Alfred Forums is always a great place to look for new workflows. If you do not find what you want there, you can also check the Alfred Workflow site (they also have a workflow that searches their site and downloads the workflow for you). Or, simply do a Google search for Alfred Workflows.

After these courses, you will also be making many workflows. Please post them on these forums so that others can use them as well. If you like it and use it, there are others who could benefit from them as well.


Information Flow in a Workflow

When you connect blocks in a workflows together, the lines represent where the output from one block will go to next. In the block that receives the output, it is placed where ever the {query} macro is found. Currently, Alfred workflows only support one macro for expansion, but there has been many suggestions for expanding this in the Forums. For example, a keyword block will output what ever is after the keyword in the Alfred prompt to the next box and places it everywhere a {query} is found.


Triggers, Inputs, Actions and Outputs

There are four types of blocks that you can use to make workflows: triggers, inputs, actions, and outputs. The name of the types help under stand how they work. Alfred organizes them into four column in the drawing board area. The flow of information on the drawing board flows from left to right. Let’s look at the different types of blocks in detail.


Triggers

Hotkeys

A Hotkey block is how you define a keyboard shortcut in Alfred. These hotkeys have global scope, which means that they are avaliable everywhere. The problem you might run into is overlapping hotkeys of other apps. Alfred will not let you overlap a hotkey that is already in Alfred, but you can easily overlap another application's hotkey. Therefore, you need to be careful on your hotkey assignment.

A trick I use is to alway have double control key. The control keys are Fn, Ctrl, Alt, and Command. If you always use two or more of these at the same time, then that will usually not overlap with another applications hotkeys. But, there are exceptions. The Help workflow is great for figuring out which hotkeys you have assigned already in Alfred. I will talk about that more in the Helpful Workflows in the Wild section.
Hotkey Input
Hotkey Input

With a hotkey, you can have Alfred forward different items to the next block. If the Argument is set to Text as shown, then the text in the text block will be passed to the next block. If Argument is set to Selection in OS X, then whatever is selected in the top most application will be passed on. If Argument is set to OS X clipboard contents, then whatever is in the clipboard will be passed on. If Argument is None, then nothing is passed on to the next block. It is then just a action trigger with no output.

File Action

A File Action will assign a new command to the Alfred browser. This is really helpful when you have something you want to do with a particular file. You can create a file action and fill it out as below.

File Action

File Action

The Name field is the name to give the file action. If you want it to accept multiple files, the click Accepts multiple files. Each file will be passed as a tab separated list. If you want this action for any type of file, then leave Types blank. Otherwise, you can drag and drop different files as examples of file types you want to process. Lastly, add a Post Notification block.

File Action on a File
File Action on a File

Now, when you browse to a file in the Alfred browser, hitting the right arrow key will bring up all the possible file actions. Press MT:Path of File and you will see the growl notification with the path to the file.

Contact Action

A Contact Action will assign a new command to the contacts in Alfred. This way, you can perform particular actions on each item of the contact form. This block has only one field.

Contact Action
Contact Action

You put the name of your command there. This one is called MT:Show Name. You can connect it to a post notification. Now, go to the Features and Contacts subsection.

Contact Action
Contact Action

If you click the + in the lower right corner, you can add a field action.

Contact Action
Contact Action

Just set the Action scroll selector to the macro MT:Show Name. Once you press Add Custom Action and browse a contact in Alfred, you can then press Enter on the name and it will display it for you in a post notification. Not too useful, but you see how it works.

Fallback Search

Fallback Search is how you would design your own fallback search option. Suppose your workflow was about a new search engine for which Alfred does not have a fallback search. You would simply use this trigger with an Open URL action with you address for your search.


Inputs

Keyword

A keyword action is a trigger on a keyword in the Alfred prompt to perform an action. You can have many instances of the same keyword and Alfred will display all of them in the prompt completion area.

Keyword Input
Keyword Input

The Keyword is the name for the keyword. Anything that the user types in to the Alfred prompt will be used in a search of the file system as well. To help not show everything in the file system for a keyword, I follow the naming convention of two or more letters for the workflow name (here it is MT), a puncuation character (here I am using :), and the unique keyword for the action I want (here I am using Echo). This will keep the drop-down area clear of unwanted search results.

After the keyword, you have a check box for allowing space after the keyword or not. If you check this, then Alfred will not pass the first space to the next block.

The argument section determines if the user should type in extra information or not. If you select No Argument, then Alfred will not expect an argument. If the user types one, then it assumes that this block is not to be used and fall through to the next appropriate action (usually the default search). If you select Argument Optional, then Alfred will pass anything that gets typed by the user, even if that is nothing. If you select Argument Required, then Alfred will wait for the user to type something before passing it on to the next block.

Then, you add a Post Notification block to the workflow. You need to fill it out as I have shown.

Post Notification
Post Notification

I will explain the different arguments in the dialog later. After pressing Save, you just need to connect them up.

Connecting the Blocks
Connecting the Blocks

To start this workflow action, you type the keyword, MT:Echo into the Alfred prompt allong with your message.

Running the MT:Echo Keyword
Running the MT:Echo Keyword

After pressing Return, you should see the Growl notification.

Growl Notification
Growl Notification

There, your first keyword input with a result!

File Filter

A file filter will allow you to search files or directories for one that matches what the user types in to the Alfred prompt.

My favorite use of the File Filter is to create a directory name searcher. Add a file filter to the workflow and name it FF for find folder. In the File Types area, drag any folder from Finder to the field. It will add public.folder to the File Types area.

Find Folder File Filter
Find Folder File Filter

Now, when you type FF in the Alfred prompt, it will display a list of folders. Typing a name will narrow down the list to just the ones that match what you are typing. When you press <enter> on an entry, the path of that folder will be passed to the next block. Therefore, if you add a Browse in Alfred block next and connect them, then you will be shown that directory in Alfred browser mode. I use this a lot!

Find Folder File Filter
Find Folder File Filter

The more advanced features will be explored in the intermediate tutorial.

Script Filter

A script filter uses a script to define what the user sees as options to select. You can write your script in almost any language you want to use. It just has to return a properly formated XML defining the different options for the user. This is an extremely powerful feature that I will explain in the advanced tutorial.


Actions

Open File

This action opens the file passed to it using the default application for that file. If you supply a program in the type area by dragging the program to it, it will launch that program with whatever file you send to it. Therefore, you can create a workflow that is the File Filter and attach it to the Open File action. Drag and drop you favorite text editor (mine is Sublime Text) to the Open File box.

Open File Action
Open File Action

Now, if you search for a file with the keyword for the File Filter and press enter, it will open that file in your editor program.

Reveal File in Finder

This one has no options. It simply reveals any folder or file passed to it in Finder. Out of the box, it works great with Finder. PathFinder does not set the necessary fields to be used in Alfred. If you want to fix that, please refer to PathFinder support is not working as intended Alfred forum post.

Browse in Alfred

As the Reveal file in Finder works, so does this one. The exception being that it opens Alfred’s browser to the location. I use this more than the Reveal File in Finder. I do find myself using Alfred’s browser as much or more than PathFinder.

Launch Apps/Files

This action allows you to create a list of programs or files that are to be launched with a keyword. By adding a Keyword input and a Launch Apps/Files block together and fill the Launch Apps/Files with the programs you want to launch (file files opened with their default program), you can make a keyword to launch your work environment for you.

Launch Applications
Launch Applications

Default Web Search

This action will take the input to the box and search for that using the search engine specified in the dialog box. You can also specify a specific browser to use.

Default Web Search
Default Web Search

Open URL

This action is used to open a url in a web browser. Your url can be completely static, or use the input to the block to create a url using the {query} macro.

System Command

This action allows you to run one of several system level commands. You would use this to trigger a system command like shutdown after a long script had finished. Or, simply create your own hotkey sequence for launching the system command.

System Command
System Command

iTunes Command

As with System Command, this action allows you to run a particular action in iTunes.

System Command
System Command

Run Script, Run NSAppleScript and Terminal Command

These three actions are for running scripts. That is a more advanced topic and will be covered in the intermediate and advanced tutorials.


Outputs

Post Notification

The Post Notification output will post a message to the user using the default method or a specified method.

Post Notification
Post Notification

The Output to: field allows you to choose from Growl notifications or Notification Center. You can also click on Sticky for it to stay on the screen until the user closes it. If you only want to display something if some text was passed to it, then check the Only show if passed in argument has content field. You can set the title and subtitle in Title and Text fields. If you are passing a file name to be displayed, you can also modify the text to show Last path component or Remove extension.

Large Type

Like Post Notification, Large Type will display the string passed to it to the user. But, this will display the information as large as possible on the screen. It is a real eye-catcher! There are no preferences for this block.

Copy To Clipboard

This output allows you to copy the given text to the clipboard. If you check Automatically paste to front most app, it will also past it to the top most application if it can. You can just type your own text in to the text box, or use the {query} macro to place the text passed to the block.

Copy To Clipboard
Copy To Clipboard

Let’s build a text expanding script. Place a keyword block with the keyword of ;add. Connect this block to the Copy to Clipboard block with your address. Check the automatically paste option and you will have a text expander to place your address in your top most application. It will also be available in the clipboard.

Run Script

This output is for running a script as the last step. That is a more advanced topic and will be covered in the intermediate and advanced tutorials.


Helpful Workflows in the Wild

There are some workflows that I have found that I use a lot, outside of the one’s that I made myself. Here are a few to get your workflow library built up:

Command Help
This workflow will create a PDF of all the keyword and hotkeys defined in each of your workflows. This is a great way to keep track of all the workflows in your Alfred and how to activate them.

RegEx Renamer
This workflow allows you to select several files in Finder and rename them according to a regular expression that you supply or one that you have previously made. I use this one quite a bit.

Regex Tester
This workflow is great to test your regular expressions on a test case. If you use a lot of regular expressions, this is a must have workflow.

Time Zones
This is great if you are working with other people in different time zones. It allows you to convert time in one time zone to another. Or, just seeing what time it is currently in a different time zone. Great for traveling as well.

Units
This workflow is great for converting almost any unit in to another unit. It is also a very pretty workflow!

UNIX file permission (chmod) converter
This workflow allows you to figure out what to use for the permisions values for unix file systems. This is great if you are programming operating system permissions for programs a lot.

Egg Timer
This workflow is great for setting up timers that repeat or are one time events. For those who have a tendency to forget appointments or time constraints, this can be a life saver.

GitHub
If you work with GitHub a lot, this is a necessary workflow. It allows you to view and work with your GitHub account and Gists.

Layout
This workflow is great for re-organizing your applications open in your desktop. Very easy to add your own improvements as well, but be careful. Updating the workflow will remove anything you change!

Colors
For those who do a lot of CSS work and have troubles getting the right color codes, this workflow is a must. I use it almost every time I work with CSS.

That should give you some good examples of workflows and get your library going. Be careful, you might end up like me with over 80 workflows! The example workflows above can also be used as examples on how to write your own.


Summary

You should now understand each of the blocks available for making workflows. In the next tutorial, I will be exploring more complicated workflows and techniques for writing them.

Advertisement