How To
Maybe You Ought To Be Using Automator
“What Automator does is it gives you all the power and ability of AppleScript, and the other scripting languages built into the operating system, but in a drag and drop format, where you’re not actually writing anything you’re just checking boxes, radio buttons, pop up menus, that kind of thing to determine what you want to do.”
—Sal Saghoian, Automator product manager, Apple Computer
I came across that quote, which appeared in a May 2006 MacBreak podcast, while researching this article. Mere days before that, I had decided for the second time to try to learn a little about Automator as part of my resolve to do things on the Mac this year that I have never done before.
I had programmed a smidgen in Applesoft BASIC years ago. It didn’t go badly, but it did convince me that I didn’t like coding. I tried AppleScript but didn’t have many applications that supported it at the time and found it a little confusing. Needless to say, that didn’t last long either. My last programming effort actually resulted in a semi-working series of macros in Microsoft Excel.
With the advent of Tiger came Automator, a drag-and-drop programming language. I tried it a few months ago for all of about five minutes, but maybe it’s time I lived up to my resolution and learned something new. If you think this is complicated or that you can’t create something useful, let’s dive right in and see what happens. There are a few things you need to know before we begin.
Before We Begin
A growing number of applications are “Automator aware”—they contain pre-defined steps or “actions” that Automator knows how to execute. If you have ever looked at AppleScript dictionaries, this is a similar concept. Actions are the individual steps that must be executed for an application to finish a task.
In the real world, if you put the right steps (actions) in the right sequence, you complete a task. In Automator, the sequence of steps needed to complete a task is called a “workflow.” In other languages or programs, these workflows might be referred to as “macros” or “scripts.” Of course, workflows can be saved, or they wouldn’t be very useful to you. There are several options for saving your workflows, but we’ll get to that in a minute. For now, let’s get to work by taking a look around Automator.
Open your Applications folder and look for Automator. You’ll recognize it by the icon of a robot carrying what appears to be a bazooka. It seems that many have started to call our little robotic friend “Otto.” And no, that is not a bazooka in his hand. It is, in fact, a pipe—representing the power of the Unix pipeline. Those of you with a better understanding of Unix than I have will understand what that means. In the MacBreak podcast I mentioned earlier, Leo Laporte suggested that Automator workflows might be a good way to give users a GUI for languages such as Perl that would normally require setting several parameters.
![automator-1](images/automator-1.png)
Once launched, the basic Automator window is fairly easy to navigate. In addition to the typical close, collapse, and expand controls, the upper left portion of the window contains a search box. Enter a keyword here and Automator will search the actions installed on your system looking for those that match what you want to do. Search results are ranked based upon their relevance to what you seem to be doing at that moment in the workflow. Entering the same keyword at different times in the workflow might result in a slightly different ranking of results.
The upper right portion of the window contains Run and Stop buttons. Workflows are usually run without having to open Automator, but we’ll get to that in a moment.
The remainder of the window is divided into three panes with the leftmost pane subdivided into two vertical sections. At the far left is a list of all “Automator aware” applications currently installed on your hard drive—including the Finder and some basic system-level tasks. The very bottom of this pane contains a folder of example workflows and a folder of workflows that you have created.
The second vertical pane lists Automator actions. Selecting a specific program icon in the left pane causes the actions listed here to change, reflecting the actions available for the program you selected. Try it and see what happens. Single-click the Finder icon in the left pane. Now you see a list of actions that the Finder understands. When you search for a function, your search results appear here as well.
While clicking on some of the Finder actions, you may have noticed that the text in the smaller pane at the bottom of the window changes. Click an action and its description appears here. Although these descriptions are written with the non-programmer in mind, some are easier to understand than others.
The dominant pane in the Automator window is to the far right of the screen. Workflows are built by dragging actions from the center pane into this area. Generally actions are dragged here in the order that they are needed in a workflow. If you skip a step, don’t fret. Drag the missing step where it’s needed and drop it in place.
Now that we’ve looked at the basics, let’s build some potentially useful workflows. After the basic workflows, we’ll tweak them a little to cover a wider range of tasks. We’re going to back up some music and set up a work environment that opens after each login.
Our First Project
When was the last time you backed up that gargantuan music folder? Let’s take care of that right now. We’ll use the first workflow I ever created to back up a specific folder. I built this to back up my music collection, but it can back up any folder you choose. One word of caution: until you are sure it’s working properly, either have a backup handy or use sacrificial data. Before turning it loose on my music collection I used a test folder with a few small files.
Before we drag the first action into place, let’s think about what happens when we manually copy a file or folder using the Finder. You must locate the source file and click to select it, drag the file to its destination, and drop it in place. If there’s already a file present with that name, you must tell the Finder whether or not to replace the existing files. We’re going to use these steps to guide our search for the right Automator actions. With that information in hand, as we complete each step see if you can guess the next step.
Since we will be using the Finder to copy the files, click “Finder” in the left hand pane. We need the name and location of the file or folder to copy, so look in the middle pane for an action called “Get Specified Finder Items.” This is how we will tell the Finder what to copy. Drag that action into the rightmost pane and drop it in place. Double-clicking the action will also move it into place.
If this action appeared in the rightmost window but didn’t expand to show a way for selecting files and folders, click the white arrow at the top of the action. Automator uses that white arrow to indicate that there are parameters available for the user to adjust.
The expanded view of this action contains a plus and minus sign. Click here, and the standard file selection sheet appears, allowing you to chose files or folders to copy. They will appear in a list inside the action. If you accidentally add something you don’t want to copy, select that file in the list and click the minus sign to remove it.
Before we leave this action, click the triangle labeled “Options.” Now a choice appears which says “Show Action When Run.” If you are going to copy the same files all the time leave, this option unchecked. I did that with my music workflow so it copies the same folder each time and runs unattended. If you want to select different files each time the workflow is run, check this option. The file selection sheet will now appear each time the action is run.
Now that we have selected the target files, what’s the next step? That’s right: tell the Finder to copy the selected files. This action has a pop-up menu to choose where the new files should be placed as well as a checkbox that allows us to tell it whether to replace existing files. The action has additional parameters accessed by clicking the Options triangle, but for now we we’ll leave those as they are.
![automator-2](images/automator-2.png)
Run the workflow once to make sure it works as expected. If the files have been copied correctly, save your workflow. Choose Save As from the File menu, name the file, and save it as an application. Right now this workflow runs when I double-click it. After we finish the other workflow, I’ll show you how to use an iCal alarm to trigger this little application to run at a specified time.
This workflow is an efficient means of copying folders to a new location. There are times, though, when you may want to copy only files that have been modified. To do that we would have to teach Automator a new trick, so we’ll save that for later.
Getting Right Down to Work
When I log into my computer, the first two tasks I perform are checking e-mail and visiting several Mac-related Web sites. Currently, I launch Mail and Safari and click bookmarks for the sites I want to visit. I could have Mail and Safari automatically launch by adding them as login items for my account, but that doesn’t get me to the sites I want to visit without some intervention on my part. I would still have to type in the names of sites I want to visit, open a new window, type in a new URL, and repeat the process until all the target sites are loaded. A boring and repetitive task—sounds perfect for “Otto.”
I want the Safari-related actions to execute first and Mail-related actions to occur last. This puts the mail window on top and I can read incoming mail before I start Web browsing. Let’s think a bit about the necessary steps before we begin. That should make finding the right actions much easier. As far as I can tell the steps have to occur in this order:
- First, I Launch Safari.
- Safari needs the names of the sites I want to visit. More accurately, Safari needs the URLs for specific sites or pages.
- Safari opens with my home page in a new window. I need to open a new window and add the URL for one of the sites I want to visit and have Safari display that page. I also have to repeat the process for each site I want to visit.
- When that’s finished, I launch Mail. It’s already configured to check my accounts upon launch. I also don’t need to enter my password. That information is stored as part of my account information.
This time, the first thing I need to do is launch Safari. Normally I would go to the Finder actions and search for one that could launch an application. That would probably work, but I found out that in this case I don’t need to launch Safari before passing it the URLs for sites I want to visit. In a moment, I think you will understand why a specific launch command is redundant. Since you did so well with the first workflow, I’m going to go a little faster with this one until I get to any difficult parts.
First Otto needs the URLs for my favorite pages. Since it’s Safari that needs the specific URLs, I’m going to look there for the first action that I need. A quick glance and I see “Get Specific URLs.” Dragging it in place I notice that the box allows me to enter multiple URLs. Make sure you enter the URLs accurately or the pages won’t load. With that done, it’s time for the next step.
Once you have the URLs in place, you need Safari to show them to you. I don’t see a Safari action that says show Web pages, but looking at the list I bet you can guess what I need to do. That’s right, I need the “Display Web pages” action. This action results in Safari documents. Safari and Automator are smart enough to know that Safari must be launched before it can create the documents. With that action in place, I don’t need a specific launch command. That’s taken care of for me.
Now that we are done with Safari, our next task is to get any new mail. We are looking for an action that will retrieve (get) new mail. Lucky for us, Otto has that action in the Mail section. Find that action and drag it into place as the next step. Don’t forget to set the pop-up menu that tells Mail which accounts to check for new mail. The options for this action allow checking all accounts or checking a single account. Set the options to meet your needs and save the workflow as an application. I set the application as a login item in System Preferences. I’ll describe how to do that in a moment. On average Automator, does these tasks eight seconds faster than I can every time I log in.
You’ve kept up with me thus far, so here’s a pop quiz. The “Get New Mail” action will either check one e-mail account or check all accounts. How do you check multiple accounts without checking all of them? No, I don’t want to run the entire workflow several times. You guessed it. Add multiple instances of the “Get New Mail” action with the pop-up menu in each one set to check a different account. Mail will only launch once, but each account you specify will be checked.
![automator-3](images/automator-3.png)
There are two things to keep in mind when you run this workflow. First, there is no error checking. If you don’t have an active Internet connection or there are other problems, Safari and Mail generate the same error behavior that they normally would.
Second, this workflow forces Safari to open pages in new windows even if you have enabled tabbed browsing. There is an action to open Web pages in tabs. Simply install this action and use it in place of the Display Web pages action. Kudos to fellow ATPM editor Eric Blair for a job well done.
There is an alternative action to open Web sites in tabs. It does require you to build a folder with Internet Connection Files for sites that you want to visit. Once you create the folder and set up the workflow, don’t move or delete that folder. If you do, the workflow will stop working until you either create a new folder or tell the workflow where to find the folder.
Making the Workflows More Useful
What could we do to make these workflows more useful? How about making them run when we want them to or with little or no user intervention. I’ll briefly share a few ideas?
Let’s look at the workflow we used to copy files. Save copies of this workflow as applications with descriptive names to help you remember what’s being copied. Don’t forget to change which files or folders are being copied. Run these workflows to copy different sets of targeted items with no more user intervention than a double-click. On one copy, go to the “Get Specified Finder Items” action and click the Options triangle. Click the “Show Action When Run” checkbox. This box will now appear every time the workflow is run, allowing you to choose different sets of files each time the workflow runs.
If you have a large amount of data to copy, set the workflow to execute at a more convenient time, like late at night. Let Automator and iCal work together. First you need to open your copy files workflow and modify the “Get Specified Finder Items” action so that it targets files that you want to copy. If necessary, deselect “Show Action When Run.” From Automator’s File menu choose, Save As Plug-in. Enter a descriptive name and save it as an iCal plug-in. Launch iCal and set an alarm for the time you want your workflow to execute. When you set the type of alarm, choose “Run Script.” Just beneath that is an option that will now say Script and None. Click where it currently says “None” and choose “Other” You will be given an opportunity to locate the script you just saved as a plug-in.
Saving a workflow as a plug-in allows it to be used as part of a specific program. Saving the previous workflow as an iCal plug-in makes it available to, and behave like, part of iCal. You can save plug-ins as part of other programs as well.
Initially, I wasn’t too impressed with the ability to save workflows as plug-ins, but I have changed my mind. When fellow editor Eric Blair saw a draft of this article, he pointed out that saving workflows as Finder plug-ins allows users to create their own contextual menu items. Imagine being able to right click files and upload them to a specific server, or create disk images with specific settings by working in conjunction with DropDMG (a utility from ATPM’s publisher).
Sometimes you might want to compare two folders and synchronize them. This could be very helpful when copying large amounts of data. In looking at the actions that shipped with Automator, I didn’t find anything that would make this possible. Fortunately there is an action available called compare folders that does just that. Once you download and unzip the file, choose Import Actions from Automator’s File Menu and locate the unzipped action. From now on, you can use this action in your workflows.
Consider saving your workflows as either applications or plug-ins. Workflows in either of these formats can run without needing to have the Automator application open.
Just like teaching an old dog new tricks, you can teach Automator new actions. The actions then become available in any of your future workflows. If you are feeling adventurous you can write your own actions in AppleScript or any other scripting language that the operating system understands. For mere mortals like the rest of us, there’s always the Automator actions at AutomatorWorld, or this download page.
I have only scratched the surface of what Automator can do. Other users have written workflows for a wide variety of repetitive tasks such as grabbing all the pictures on a Web page. My next project is a workflow that will copy files from a work-in-progress folder to a memory stick drive. I’d like to have the files get copied while I am asleep, log out of my account, and put the computer to sleep. I’ll keep you posted.
Also in This Series
- Give Alert Sounds a Little Personality · March 2012
- Create Your Own iPhone Ringtones · February 2012
- Create Your Own Homemade Audio Book · December 2011
- Upgrade to Lion Painlessly · August 2011
- Make the Most of TextEdit · July 2011
- Using the Free Disk Utility on Your Mac · May 2011
- Making Use of QuickTime X · March 2011
- Making the Most of What’s Already on Your Mac · February 2011
- Making the Most of What’s Already on Your Mac · January 2011
- Complete Archive
Reader Comments (27)
I do have a question, though: I saved the workflow as an iCal plug-in, and set a recurring event to run the backup. However, in your directions you say to choose "Run Script" under Alarm Type, and choose the plug-in. First, I had no idea where the plug-in was saved to, but finally ran it to earth in the Library/Workflows folder. But it was grayed out and unselectable. So I fired up the Automator Help, which indicated that rather than "Run Script" I should choose "Open File" for the Alarm Type, at which point I was able to choose my saved workflow from a pop-up menu. I guess I won't know if it's right until 2 a.m. next Saturday morning.
I am sure that Automator is capable of more despite some limitations. Depending upon reader response, and how my skills progress, I may be writing more about this in the future.
Imagine being able to right click files and upload them to a specific server, or create disk images with specific settings by working in conjunction with DropDMG (a utility from ATPM's publisher).
Same idea. :-)
May I also recommend automator.us as a place to download free actions and projects.
Keep up the good work!
I am not sure if the mail action would allow send a different message to each recipient (other than to randomize the pictures). Saving a different copy of the Automator script for each recipient would do the job but that seems like a lot of work.
The MacBreak podcast that you did in May with Leo was quite helpful to me. It gave me an excellent visual representation of Automator's basic concepts. I'm finally getting time to check out MacBreak 08 the Automator Life poster. It looks like a great idea and a creative use for Automator.
I fully intended Mail to send the same (generic) message to all those whom I've designated with "birthdays" in Address Book - personalised messages would be OTT. Still, wouldn't it be wonderful to get a reply from a friend whose B'Day you forgot saying how thoughtful you were to remember all because Automator had "kicked in" on that day which you created in Address Book a year ago?
Check them out here.
Do go and tell me I can apple script those options. It defeats the point of automator
I do agree that everyone should at least play with it and be aware of what it does. It may help to look at it as sort of a Visual AppleScript, or an AppleScript for Workflows.
Right now Automator feels a lot more like a technology demo than something useful. Maybe that'll change over the next couple of years.
While I have seen some actions which make it easier to save and pass results among actions, I have not seen anything that handles conditionals. I suspect that for the moment conditionals must be handled using either AppleScript or one of the other languages that Automator supports.
By all means, if you are well-versed on this, a follow-up Automator article from one or more of you would undoubtedly be welcome.
The Automator team is hard at work developing the next version of Automator for Leopard. We're examing all of the issues raised here and I think you'll be pleased with the results.
Meanwhile, there is much you can do with Automator right now in Tiger that you may or may not be aware of. For example:
1) You can run workflows within workflows by adding the Run Workflow action to your workflow.
2) Automator is not limited to AppleScript. Automator actions are written in Xcode and as such can use any language or frameworks supported by the OS. Xcode comes with three Action templates: AppleScript, Cocoa, and Shell. These templates can expose any available OS tools, such as PDF Kit, Core Image, Core Data, or Core Video.
3) Automator includes actions for easily adding your own custom code to a workflow. If there's not a action for what you want, you can use Run AppleScript, Run Shell Script, or Run Webservice to create your own action to fill the gap.
4) New Action collections are being released all the time. THere are Action Packs for MS OFfice, Adobe Photoshop, InDesign, FileMaker, ARD, and more.
For a thorough overview of what Automator is, how it works, and how to expand it's abilities -- along with sample workflows and downloads -- vist AUTOMATOR.US
And thanks to everyone for contributing!
For that workkflow to operate correctly you must open Safari's Preferences and enable tabbed browsing from the Tabs pane. You must also go to the General tab and change the Open Links from applications to "in a new tab in the current window". The action created by ATPM editor Eric Blair does not require additional configuration.
If you are using the other action you must complete an additional step. Create Internet Connection Files for the sites that you want to visit. Go to the site that you want and drag a bookmark for it to a convenient location, I put them all in a single folder. In that first step where it says "Get Specified Finder Items" point it to the location of your connection files.
I have tried several ways to get this working with Firefox. The workflow that relies on Internet Connection Files almost works. In researching this article I have not found any similar Automator actions for Firefox. It should be possible to create a similar Automator action for Firefox but it will probably have to be done in something other than AppleScript since Firefox appears to have a limited AppleScript vocabulary.
Thanks for that information Sal. I was pretty sure this could be done with either AppleScript or one of the other supported languages.
I hope to have a few more articles in the future as my skills improve.
Hopefully there will be some updates to Automator when 10.5 is released. If so, I will probably do a "review" if there are any significant changes.
THAT is EXACTLY what I want to do. When will that tutorial be available? Or do any of you know of a program (not a backup program) that will allow me to do this?
Thanks!
David
It can be done with a workflow that contains the following actions: Find Finder Items and Copy Finder Items. If you set the "Find Finder items" option to "Show When Run" it allows selrction of multiple criteria "on the fly" In the Copy Finder Items Step select a destination.
Be careful where you tell it to start the search. If you use this workflow to search the entire hard drive and only look for files modified today, you will not only get your document files in the results but several system files as well.
There's also probably a script out there that would assist in file selection as well. This script could be added an Automator Run Script action.
I am expermenting with a piece of software called Hazel from Noodlesoft.com. It provides a means setting more complex file selection rules. These results are supposed to be able to trigger Automator actions.
Add A Comment