Discovering Automator by Hanaan Rosenthal • Automator, A Mac OS X Tiger automation app for the rest of us
 
 
Chapter 1: There’s Otto in Automation
First there were pencils, rulers, typewriters, and graph paper. We used them to do the work we needed, and although they were tedious to use, the work got done.
Then, there were computers. First we thought that the faster they are, the faster we could get our work done. It was not so. The faster and more complicated they got, the more we needed to know about them. For most, they became just another way to do work, but after figuring in down time due to equipment malfunction and lack of training, computers did not allow us to work much faster than the good old tools they replaced. 
So what gives? What is the silver bullet that makes the most incredible and widespread technological advancement of the Twentieth Century actually live up to its hype?
That bullet is automation. No, I don’t suggest you make your life even more complicated by adding more programs to your Mac that do more things that can break and slow you down. Let’s try to understand the problem: If you only tell your computer to do one thing at a time, then it can’t get much faster than you already are since you are the one telling your Mac what to do. And today’s Macs are very fast, so by doing just one thing at a time, your faithful Mac isn’t being used to its fullest. Instead of multi-tasking and running parallel processes (don’t gloss over now), your Mac has to stop after each command and wait for you to tell it what to do next. This is the same as having the high-speed train stop at every house collecting and dropping off passengers. Ride this train and yes, you’ll get somewhere eventually, but it certainly won’t be a fast or efficient trip.
There is, however, a better way to use computers, and it is called automation.
Automation is the act of asking the computer to do a few things at a time. Sometimes, you can ask the computer to do two or three things before it needs your input, some people can even teach the computer how to work for days without requiring any human intervention.  Web servers are a good example of that, but that doesn’t help you save any time, does it?
While automation always existed in some form or another, it was, like many things in life, reserved for those who could afford it.  This, as you are about to find out, is all about to change.
Meet Otto, the Automator
In case you haven’t noticed, Automator’s icon is a cute robot holding a pipe. But one thing you might not have known is that the robot has a name: Otto. Being the first human-named Mac application, Otto leads a very private life. When it comes to automating tasks on your Mac, Otto’s not shy to speak up. In fact, Otto leads a revolution that not only alters the way you use your Mac, but it could also force psychiatrists around the globe to rewrite their definition of the Mac-envy syndrome.

How Automator came to be
At Apple, a dedicated team of developers and computer-usability experts, headed by Sal Sohgoian, are working day and night to improve the way we all use our Mac. Their focus: Automation. 
While the programming language they bring to life—AppleScript—is a hit among folks who want to automate their Mac, the team was looking for ways to bring Mac automation to the masses in a big way. They wanted to make automation so easy that anyone could do it without any programming at all.
One of the original ideas the team was toying with was and old UNIX form of chaining multiple commands into a single flow. This method is called a pipeline, but it was still UNIX, and to use UNIX, well, you need to know UNIX.
The idea evolved and eventually grew from a mere extension of UNIX pipeline into a full-blown Mac automation utility we know as Automator. 
One hint of the old idea remains, however. That cylinder thing that Otto is holding in his famous icon-picture is a pipe. The pipe that signifies the original pipeline idea. 
Automation for the Rest of Us
As noted earlier, Automator brings computer automation for the rest of us. You don’t need to know a scripting language like AppleScript or some other geeky language like Perl, Python, or Ruby to control your Mac any longer. What “automation” means to you will vary, but rest assured, if your work includes repetitive tasks, you can use Automator to handle these mundane tasks for you. Automator performs them quickly and accurately, and best of all, Otto won’t whine when you give him a job to do.
How can Automator do things you want done?
This is certainly the foremost question on the minds of the Automator team. They knew that while people wanted to automate very different things, there are many similarities between what they would want to automate. Just like snowflakes, no two Mac users are alike (no matter how hard we try to assimilate with Steve). The concept they came up with is a winning combination of versatility and ease-of-use.
Automator allows you to automate tasks by providing Actions that you combine together in a workflow. To accomplish the task, all you need to do is run the workflow from Automator’s window, or  save the workflow as a standalone application. You’ll learn more about the different ways to save Automator workflows later in Chapter 9, but for now, just know that each of these Actions does one small thing and can be tied together with other Actions to help you get your job done.
What is a workflow?
A workflow is a list of tasks to be performed in succession multiple times. A workflow is only a workflow if you execute it more than once, otherwise it is just a collection of activities you do.
Imagine your morning routine: You wake up, shower, brush your teeth, get dressed, make coffee, drink coffee, pick up the paper, get in your car, and then drive off to work. Each thing on this list is an action that makes up the workflow you repeat each workday. (Lather, rinse, repeat.)
Other people do similar actions but may do them in a different order. Some may make tea instead of coffee, some may skip the paper, and so on. The point is, if Automator was designed to help people with their daily routine, it would look similar to the chart shown in Figure 1.


Figure 1. Y our daily routine consists of a series of actions that flow together, much like the Actions in an Automator Workflow.
Each Action in your daily routine fits neatly together, just like the pieces in a puzzle. If everything goes according to plan, your day moves along swimmingly. However, hit that snooze alarm one too many times and your entire day can get out of whack. Automator workflows are much the same, in that the Actions you drag to the workflow area need to fit together just like the pieces in a puzzle. Some Actions just won’t work together, but by sticking another application’s Action in between, you could get the behavior you are looking for.
How do I use workflows and actions?
After you drag a few actions into a complete workflow, you can run the workflow right from within Automator. This is mainly done for testing purposes while you are building the workflow.Once the workflow is complete, it can be saved in many ways including in a workflow file you can run directly from Automator, an application you can run from any Mac running Automator, and even as plug-ins for programs such as iCal, the Finder, and others. All these will be discussed in Chapter 9.
The most common way to save a workflow is as an application. The benefit of saving your workflow as an application is that you can drag and drop files and folders on the application to invoke the actions in the workflow, but most importantly, you can distribute the Automator application to other users. For additional information on how to distribute and use workflows on your Mac, see Chapter 9.
Now that you know the basics of what Automator is and a bit about its interface, let’s dig-in and create your first Automator workflow. In the next section, you’ll create an Automator workflow that looks for songs in your iTunes music library that match a certain criteria. iTunes then compiles those songs into a new playlist and uploads that playlist to your iPod. This  Automator workflow is sure to come in handy, especially if you are one of the millions toting around an iPod these days.
Getting Hands-on with Automator
Whenever you launch Automator, you get a window with three main columns: Two columns to the left that are already chock-full of things, and an empty column to the right, which is where you build your Automator workflow.
This appears initially to be Automator’s only window, much like iTunes or Mail has one window each. In fact, what you see is an untitled Automator document. Just like in programs such as Word or Photoshop, you can have multiple documents, each with their own name and settings. Likewise, if you want to create more than one Automator workflow, you can just choose File  New (-N) from the menu bar to create a new, blank, untitled Automator document.
An Automator document is also referred to as a workflow. As mentioned earlier, a workflow is a collection of actions your Mac can perform. Right now, the workflow portion to the right of the window is empty since you have yet to give it any Actions to perform. The columns to the left have every Action currently available for you to use in the workflows you create.
The same Action can be used in as many workflows as you want, and even more than once in the same workflow.
Getting Around Automator’s Window
Figure 2 shows Automator’s document window in all its glory. As you can see, there’s a lot going on in that window, so before we go any further, let’s take a quick run-through of the different sections of Automator’s user interface:


Figure 2. Automator’s window, as you can see, has a lot going on, but once you get used to its interface, Automator can be a really powerful tool to have at your disposal.
Action search field
This field allows you to plow through hundreds of Actions to quickly find the one you want.
Library list
The Library contains a list of the applications that have Automator Actions, as well as some sample Workflows you can try, and a folder in which you can store the Workflows you create. To see the Actions available for an application, just click on the icon for the application you want to control; the Actions appear in the next column to the right.
Actions list
Whenever you select an item in the Library list, you’ll see a new list of Actions appear in this column. These are the Actions you can use to control that particular application. With most Actions, their name should give you a good indication of what they do, and in case it doesn’t, or if you need additional information about the Action, all you need to do is look down below in the Info area to see a description for that Action item. To apply an Action to a Workflow, you just drag the Action to the Workflow area to the right. 
Workflow area
This is the main course! This area is blank when starting a new document. Actions in the Workflow area are run, one by one, when the workflow is executed. 
Info area
The info area shows important and useful information about the selected action.

What’s in the Library?
At first it appears as if the Library has a list of icons with names that look a lot like a list of applications. In general, Actions are organized based on the application they automate. Any Action that modifies files or folders, for instance, will be in the Finder’s Library, and any Action that deals with general text will most likely be found in TextEdit’s Library, even if it doesn’t have anything to do with TextEdit.
Some other text applications such as BB Edit ship with their own Automator actions. These actions appear under the category of that specific application.
The Library that a specific Action appears under is very much up to the developer of the Action. Therefore, you may not always be able to find an Action by looking in a specific application’s Library. 
The best way to find an action is to click on the Applications folder at the top of the Library, which reveals all of the Actions installed on your Mac, and then search for an Action by using the Search field at the top-left of Automator’s window. All of the Actions with that word anywhere in the description or keywords will show up in the Actions column. Enter more words to narrow your search.
For example, let’s say you are looking for an Action you can use to resize an image. If you type “resize” into the search field, nothing shows up in the Actions column. Well, that’s not good. So, you backspace over “resize” and type in “image” since you know you want to work with an image file. You’ve still got a large number of Actions to look through in the Actions column, but you can see your choices have been narrowed down. If you scroll through the list, you’ll see an Action named “Scale Images.” Well, since scale and resize are pretty much the same thing, this must be what you’re looking for, so grab and drag that over to the Workflow area.
The Library column also includes a couple of folders which you can see if you close the Applications folder in the list. To close the Applications folder, click the little black flippy triangle (also known as a disclosure triangle) to the left. When you click that triangle, the Applications folder closes, hiding its contents, and lets you see any additional items in the Library column without having to scroll up or down through the list.
By default, you’ll find two other folders in the Library column: Example Workflows and Sample Workflows (see Figure 3). Later in the book, you’ll see how to use these folders to organize your workflows.


Figure 3. The Library column, with the Applications folder closed, reveals the Example Workflows and My Workflows folders.
So now that you’ve had your little tour of Automator’s interface and you’ve figured out how all that works, let’s get to create your first Automator Workflow. In this next section, you will be walked through the process of creating a Workflow that creates an iTunes Playlist based on certain search criteria. So, hold on tight, it’s time to put Otto to work for you.
Creating Your First Automator Workflow
Okay, it’s time to get your hands a little dirty and put together a cool Workflow that you use to create customized playlists for iTunes, which you can later run and upload  to your iPod. Before you get started, though, you’ll need to make sure Automator’s running. If you don’t see Otto in your Dock, open a Finder window, select Go  Applications (Shift--A) from the menu bar, and then double-click on Automator’s application icon.
iTunes Playlist Creator
For your first project, you’ll create a Workflow that creates an iTunes playlist that includes all the songs that have the word “love” in the title. And since we could all use a little love these days, let’s get started:
Start with a fresh Automator Workflow window.
To create a new Automator window, select File  New (-N) from the menubar.
Next, locate the first Action and add it to the Workflow.
Since you will be dealing with an iTunes-related workflow, the Action you want is most likely found in the iTunes Library. So, in the Library column and inside the Applications folder, click on the iTunes icon.
As you can see, the Actions column now shows only those Actions related to iTunes. There are, however, quite a few of them, and due to the similarity in Action names, it is sometimes difficult to fish out the one Action you want.
Since what we want to do is find songs, the first Action you’ll want to use is the Find iTunes Items Action. To help you locate that Action among all the iTunes Actions, type the word “Find” into the search field at the top-left of the window. Now, the list is narrowed down to only a handful of items, as you can see in Figure 4.


Figure 4. The Actions shown in the Action column have been narrowed down to ones matching the word “Find.”
Add the Action to the workflow
To add the Find iTunes Items to the workflow, either double-click on it in the list, or drag it from the Action column to the blank Workflow to the right.
Just for practice sake, add a few instances of that Action.
To remove the excess Actions from your Workflow, click the X button at the top-right corner of the Action, as shown in Figure 5.


Figure 5. Click the X button at the top left of the action panel to remove it from the workflow.
Configure the Action in the Workflow.
Now that you have added the action to the workflow, you need to configure it to do what you want. Start by changing the Find pop-up menu to read “songs” instead of  “sources.”
Next, change the Whose: search criteria to find the songs whose name contains the word “love.” Change the settings in the Action panel in the workflow area to match those shown in Figure 6.


Figure 6. The configured Find iTunes Songs action.
Finish the workflow.
Now that we’ve told iTunes that we want all the songs with “love” in their title, the next step is to add a second and last Action to the Workflow. This action takes the songs found by the previous action and adds them to an iTunes playlist. Let’s first do that and then you can look at some cool things that Automator is doing behind the scenes.
To find the next Action, you’ll need to clear the Action search field at the top-left of Automator’s window. To do that, just click the X button at the right of the search field, as shown in Figure 7.


Figure 7. Click the X button to clear the action search field.
With the Search field cleared, the next thing to do is  to find the Add Songs to Playlist action. To locate it, type the word “Add” into the search field. Notice that one of the actions is the Add Songs to Playlist; double-click it to add the Action to the Workflow.
After adding the new action, select the “New Playlist Named:” item, and type “love songs” into the text field to the right.
Your workflow should now look exactly like what you see in Figure 8.


Figure 8. The finished workflow.
How the Actions are linked
If you to take a quick look at the place where the Actions connect in Figure 8., you’ll notice that the first action lists iTunes songs as the output and the second action lists iTunes songs as its input. Also notice that the two connect nicely together. Why wouldn’t they? The second action wants what the first action can give!
How Actions connect together is one of the fundamental principles that makes Automator tick. If you simply ran one Action after another, you would be very limited with what you could do since there would be little or no communication between Actions. In Automator, each Action has the ability to provide a result for the next Action to use, as well as the ability to use the previous Action’s result as its own input.
In the case of the iTunes Playlist Creator, the first action finds a few songs in iTunes, passes a reference to these songs to the second Action, which then does nothing more than take the songs passed to it and places them in a new playlist.
There are times when an Action may not require any input from the previous one, or may not return any result to the following Action. In either case, understanding the communication from one Action to the next is an important part of Automator, which is covered later in Chapter 4, Actions and Workflows. 
What do action connections look like?
The connection between two actions is illustrated graphically between the two actions, to the right side of the window. Since not all actions’ results fit well with other actions’ inputs, Automator shows a graphical representation of the connection. This gives you some idea regarding how well the two actions will communicate. As you can see in figure 1-9, the first action’s result of iTunes Songs works well with the following action’s input of the same type. If the connection between actions is not working well, the result and input type will appear in red.
It is important to remember that some actions don’t have results or don’t accept input at all. Also, connection that appears good may produce the same result, and connection that appears broken may appear so because the workflow does not require a good connection at this point.
This subject will be thoroughly covered in Chapters 3 and 4.


Figure 9. The connections between two actions.
Running the workflow
Now that you’ve built the iTunes Playlist Creator workflow, it’s time to put it to the test and actually run the thing. To run the workflow, simply click the Run button at the top-right of the window, as shown in Figure 10.

Figure 10. The Run Workflow button and the Stop Workflow button.
As the workflow executes, watch the bottom left corner of each action panel. As each Action executes, a progress indicator starts spinning, as shown in Figure 11. After that action has finished its task, the next Action started to run, the finished Action shows a checkbox in a green circle at that same bottom left corner, as shown in Figure 12.


Figure 11. The progress indicator turns as the action executes.


Figure 12. The checkbox in green circle shows as the action is done executing.
If the action failed to run, an X in a red circle shows up at the bottom-left corner of the Action, as shown in Figure 13.


Figure 13. The X in red circle shows if the action has failed to execute. This may or may not accompany an error message.
Saving the Workflow
Saving the workflow is simple. In fact, it’s just like saving a document in any other program. To save the iTunes Playlist Creator workflow, just go to the File menu and choose Save, or use the -S shortcut. When you do, a Save sheet flops out of Automator’s window, as shown in Figure 14.
From the File Format pop-up in the Save dialogue box, choose Workflow, then select the folder where you want to save the workflow, and click Save.

Figure 14. Save Workflow dialogue box.
Ha! There’s my workflow!
If you haven’t noticed, scroll to the bottom of the Library column and take a peek in the My Workflows folder. Notice that the workflow you have just saved is right there! Actually, any workflow you save will appear there.
You can create more folders by clicking the + button. To add workflows to the new folders you create, drag them there directly from the Finder.
A good place to save your workflows is in the Workflows folder inside your user’s Library folder.
What’s next?
This chapter gave you a solid introduction to Automator and let you get your feet wet. You were introduced to the interface of the Automator document window, which is also called a workflow. You created a working workflow by linking actions together, and finally you saved your workflow for later use.
In the next chapter you’ll get a closer look at the way actions work. You will see how actions are organized, how to better find the action you want, and of course, you will be building more cool workflows! 


<-- Previous Chapter - Next Chapter -->

Home.htmlCh2.htmlshapeimage_2_link_0shapeimage_2_link_1