Automator: The Ultimate Automation Assistant

Automator is an incredibly handy automation assistant for OS X. Instead of writing lines of code as in AppleScript, Automator allows you to string together preset actions through an easy to use drag-and-drop interface. The result is no-brainer automation on the fly.

This tutorial will cover a number of basic Automator features including how to work with application-specific actions, creating variables, embedding AppleScripts, and recording custom actions. Let’s get going!

Getting Started

Open Automator and create a new workflow. You should see a wizard (a helpful menu, not a guy with a pointy hat) like the one below.

The Wizard

The Wizard

When you select what kind of script you wish to build, Automator will start you off with an action you’re likely to use. However, we’ll be starting from scratch so just choose the “Custom” option.

Automator Main Window

Automator Main Window

When you start a new custom workflow, you’ll be brought to the main window (pictured above). The Automator interface has been streamlined so that even the most inexperienced users can create automated tasks with ease. The main window contains three columns.

The first of these columns is the action library. Actions are neatly categorized by function. The second column contains the actual actions. Without a category selected, this column will contain every action in your library. These results can be filtered by searching or selecting a category. For instance, if you wish to see only “Mail” related actions, simply click on the Mail category. When you find an action that sounds like it might be what you want, click on it and check out the action information in the bottom left of the main window.

Info Window

Info Window

This window shows you a brief description of the action along with what the action will accept as input and output as a result. Don’t worry if this doesn’t make much sense yet, it will be clearer when we start building our workflow. If the description sounds like what you want, click and drag the action into the area that says “Drag action or files here.” Each action, when placed in the workflow, has its own set of options and functions that you can customize to your own purposes.

An Example Action

An Example Action

Notice that if you drag multiple actions into the workflow they link together and are rearrangeable. Certain actions require an input of some kind, which can be obtained from a previous action. The link represents the output of one action becoming the input of the next action. To illustrate how all this works, we’ll create a workflow that automates a simple task.

The Algorithm

As a freelancer, I frequently receive emails that contain something for me to do. I usually create events in iCal for these items so that I can view all my deadlines for the week at once. To facilitate this process, we’ll create a workflow that grabs the selected text in Mail and puts it into a new event in iCal. Creating an algorithm is the process of breaking down what we want to do into manageable steps:

  1. Show Mail
  2. Copy the selected text to the clipboard
  3. Put the text from the clipboard into a variable
  4. Create a new event in iCal containing the text of the variable

As you can see, our algorithm is fairly short and straightforward (meaning this should be easy). Let’s get started!

Step 1: Embedding AppleScript

Before we build the workflow you should know that there are more efficient methods than the way we’ll be doing it. The reason for this is that I want to show off a few specific features that you might miss otherwise. With that in mind, let’s proceed to the first two steps of our algorithm.

We need to activate Mail and copy the selected text. Chances are, if you have text selected in Mail, it will be activated. However, when you run the action, Mail will no longer be the frontmost app. Consequently, we need the action to switch the focus back to Mail. We are going to accomplish this through a simple AppleScript.

This is the part where you say “Hey I thought this was an Automator tutorial! You can’t make me write code, I won’t do it!” The truth is, since Automator uses prebuilt actions, you’ll find that you sometimes run into limitations. If there isn’t an action for what you want to do, you’re stuck. Unless of course you know how to embed AppleScript into your actions. This function gives you the freedom to only code those portions of your automation workflows that aren’t supported by Automator. Nifty no?

We’ll keep the code here incredibly simple but you should check out my Ultimate Beginner’s Guide to AppleScript anyway so you can learn to write your own snippets of code to insert into your workflows. The first order of business then becomes locating the action that allows us to embed an AppleScript. Click on the “Utilities” category in the first column to find all the system-related utility actions. About halfway down the column of actions you’ll see one titled “Run AppleScript.” Click on this action and look at the info window.

AppleScript Information

AppleScript Information

The description for this action reads “This action runs the specified AppleScript.” Since this is exactly what we want, click and drag the action into the drop zone of the workflow. You should see the following window in your workflow:

AppleScript Window

AppleScript Window

For our purposes we don’t need to worry about anything but the section that says “Your script goes here”. Naturally, this is where we will place our script. Place the following text in that section and hit “Enter” to compile (the one on the far right of the keyboard near the number pad):

1
2
3
tell application "Mail"
     activate
end tell

The action should now look like this:

Mail AppleScript

Mail AppleScript

This script is pretty straightforward and will simply make Mail the active application. If you hit the “Run” button in the top right of the Automator window, the script should run and activate Mail. If this does not happen, double check for errors.

Well there you have it, you are now equipped to work around many of the limitations of Automator by embedding an AppleScript that will do the heavy lifting. Now let’s proceed to the second step where we learn another useful trick.

Step 2: Recording Actions

Automator allows users to perform a given task or set of tasks while it records the process into an action. Upon hearing this, many people have the tendency to think that all their problems have been solved and that they’ll never use another feature. After all, if you can simply record what you want to do with little effort, why go through all that other stuff?

The truth is, recording actions in either Automator or Script Editor can give you mixed results. Like the magic wand tool in Photoshop, you’ll use it less and less as you become more proficient. For now I recommend experimenting with it on your own to get a feel for what does and doesn’t work.

Before we record this step, go to Mail and select some text from a message, then switch back to Automator. To begin recording an action, just hit the big record button at the top right of the main window. Now switch back to Mail and hit “Cmd-C” to copy the text. Finally, hit the stop button on the floating Automator window.

Recording Mail

Recording Mail

Now switch back to Automator and look at your workflow. It should look something like this:

Your Workflow

Your Workflow

Automator has conveniently broken up your actions into steps. For our purposes, we only need the “Press Cmd-C” step. Delete any others you might have by clicking on them and hitting “delete.” Notice there are a couple of options associated with this action (Timeout and Playback Speed). Feel free to play with these, but since we don’t really need them changed I’ll just leave them where they are.

Step two is now complete! The point of this step was to show you that you can record long, complicated actions and keep only those steps that are important for the workflow.

Step 3: Getting Text from the Clipboard & Working with Variables

In order to put our copied text into a variable, we need to tell Automator to “get” it. To do this we’ll click on the “Utilities” category in the first column. In the second column, about five from the top, you should see an action titled “Get Contents of Clipboard.” Click on the action and read the description in the bottom left of the window.

Notice that the input requirement and result both say “text.” This means that the action will take the text (only text will work) from the clipboard and will spit that text out to the next action. Throw this action into your workflow under the “Watch Me Do” action.

Now click the little results button on the clipboard action. The action will extend and show a window that says “Run workflow to see results.” Making sure you still have text selected in Mail, run the workflow by clicking the play button at the top left of the window. You should see something similar to the following:

Clipboard Results

Clipboard Results

The text that you selected in Mail should pop up in the results window. This lets us know that everything we’ve done up to this point is working perfectly. Now we need to take this text and put it into a variable.

If you’re unsure of what variables are and how they’re used, I refer you again to my Ultimate Beginner’s Guide to AppleScript which explains variables in detail. To put it briefly, a variable is a way to store information to be called upon later.

Above the first column in the Automator window you should see two buttons: Actions and Variables. By default, the Actions button is selected. Click on the Variables button. You should see a list of the types of variables Automator supports. Since we know that our last action output text as a result, scroll down the list and find the “New Text” variable. Drag the new text variable into the workflow.

Get a Variable's Value

Get a Variable's Value

You should see an action pop up in the workflow (Get Value of Variable) and a list at the bottom of the workflow which holds all the variables in a given workflow (we only have one). In the list at the bottom, double click the “New Text” variable and rename it something useful like “clipboardContents.” That’s all there is to creating variables in Automator, now we can call up this bit of text wherever we need it!

Step 4: Creating an iCal Event Using the Text our Variable

With the Actions button selected for the first column, click on the Calendar category in Automator. Near the bottom of the list there’s an action titled “New iCal events.” Drag this to the end of the workflow. Now drag the clipboardContents variable from the list at the bottom into the “Name” field of the action. This takes the text stored in the variable and puts it into the title of the event. This will enable us to create any number of unique events based on the text in the clipboard.

Notice there are several other options in this action, like the start and stop time of the event, the date, and the calendar you wish to put it in. As you can imagine, if we’re creating events from emails, this information will need to be different every time we use the workflow.

Fortunately, Automator allows for user input on a given action. Click on the “Options” button along the bottom of the action. Now check the box that says “Show this action when the workflow runs.” Now when we run the action we’ll be presented with a window that allows us to set the information for the iCal event we are creating.

Creating a New Event

Creating a New Event

Quick Recap

Our workflow is finished! Before we test it, make sure you’ve placed all the actions in their proper sequence. Here’s an ordered list for reference:

  1. Run Applescript (with the text above)
  2. Watch Me Do (containing only the “Cmd-C” item)
  3. Get Contents of Clipboard
  4. Get Value of Variable
  5. New iCal Events (With “show this action” checked)

Saving & Running

When you are finished with the action, you can save it as a workflow or an application. I recommend saving it as an application and throwing it in your dock. Now when you select text in an email you can click the application and it will automatically create an iCal event using the selected text!

If you’d like to take a look at the finished workflow, we have made it available as a download: Download Automator Script – Have fun!

Conclusion

You should now be adequately equipped to start creating your own workflows. I hope you’ve enjoyed this post and learned as much as I have from writing it. Let us know what you’re going to automate! You can find a bunch of third party actions to help you out at Apple’s Downloads Page.

Also, this is the second article in my series on automation and I’m looking for ideas on what to write next. Tell me about the mundane tasks that you’re forced to complete over and over again. I’ll see if I can take your input and create another tutorial using either AppleScript or Automator.

Feel free to contact me with your AppleScript/Automator questions using the comments below or by sending me a tweet: @secondfret.


  • Pingback: Internet Marketing Email » Blog Archive » Automator: The Ultimate Automation Assistant – Mac.AppStorm

  • Pingback: Internet Marketing Email » Blog Archive » Automator: The Ultimate Automation Assistant – Mac.AppStorm

  • http://foxyturkey.com Yigit Ozdamar

    It’s nice article for beginners. Thanks!

  • http://twitter.com/cupcakeluv Brooke

    i would love to figure out how to automate changing icons for different apps, even menubar icons for some. auto update blows away all my changes, like my much improved skitch menubar icons.

  • http://www.twitter.com/secondfret Joshua Johnson

    Hmm, I can’t find any Automator actions that could accomplish the task. AppleScript would be the way to go. I suggest checking out the Finder AppleScript dictionary to see if you can find anything about changing icons… and reading my AppleScript tutorial on this blog :)

  • http://twitter.com/cupcakeluv Brooke

    look what I found! http://blog.iconaholic.com/2009/05/automate-changing-icons-for-apps/
    its an automator action thingie for changing app icons. it explains how to edit theirs for your apps, though, it doesnt fully explain how the automator workflow was made.

  • http://www.twitter.com/secondfret Joshua Johnson

    Good find! The workflow is pretty simple (in fact I should’ve thought of it!). It just takes the new icon file and copies it to the hidden resources folder inside an application. This effectively replaces the application’s current icon.

    • http://twitter.com/cupcakeluv Brooke

      yes, and thats the same way to change an app’s menubar icon. I wonder though, is there a way to add a step to first duplicate the items in the resources folder that you are about to replace? just as a way to have a backup, I always do that, and leave the duplicate right there in the resources folder. I’m totally new to automator, so I’m sorry if thats a really dumb question.

      • http://www.twitter.com/secondfret Joshua Johnson

        Under Finder actions is “Duplicate Finder Items”, throwing that in before you perform the replace action should give you a backup of the file you’re replacing. Voila!

  • Pingback: Advanced AppleScript Techniques | Design City

  • Pingback: How To Be Effective | David Turnbull

  • Danny

    I’ve been trying to figure out how to use AppleScript and/or Automator to do something in Mail that would make organization of messages easier for me. Here’s the workflow I have in mind. (1) Select some messages in my Inbox, (2) choose an existing mailbox to move them to OR create a new mailbox, (3) move them to the chosen existing or new mailbox. Any suggestions on how to do this? Thanks!

  • http://www.mluedeke.de Micha

    Nice tutorial, thanks a lot!
    I’ve both tried and searched to find or create a solution for that Mac problem to convert multiple files in Handbrake into iPod/iPhone suitable movie format (that definitely MUST work somehow, right?!), but so far I haven’t succeeded. :(

    I would even pay money at fiverr.com for that! :)

    • hans Waasdorp

      I can do that for you hit me up if you still need it.
      servergenius at gmail dot com

  • Dan Markovitz

    Josh, I’m struggling to make a workflow that launches Dropbox everyday at night, lets the app run for 2 minutes, and then quits the app. I’ve created both a workflow and an application, tied them to an iCal event…and failed. I can send you a screenshot of what I’ve built and maybe you can help. Thanks!

  • http://blogmartinvaresio.com.ar Martin

    Mac problem to convert multiple files in Handbrake into iPod/iPhone suitable movie format

  • Ezea

    As soon as I add the iCal event, the Automator no longer can get the variable. Do you have any idea what I might be doing wrong?

  • Pingback: 10 Awesome Uses for Automator Explained | Mac.AppStorm

  • Pingback: 10 Awesome Uses for Automator Explained | Design City

  • Kirt

    I want to copy a line of text to the clipboard, drag a filename to an automator button, and have it append the text from the clipboard to the end of the filename. Automator has a rename function that allows you to append text to the end of the filename, but it won’t accept a variable input. What is the point of variables in automator if it won’t accept them in text fields? Is there another way to accomplish my goal?

theatre-aglow
theatre-aglow
theatre-aglow
theatre-aglow