Step 6: Part of the fun of working with Automator is that you can test your workflow right away, even before it’s finished. Click the Run button at the top right of the window.
A dialog appears and asks you to pick a folder! (Click Cancel or OK to dismiss it.) Our workflow is working. Of course, so far it doesn’t do anything with the chosen folder.
Step 7: Let’s fix that. Given a folder, we need to get all the files inside it. Look back at the list of actions. Hmmm… Get Folder Contents looks promising; click it and read the description. “This action gets the items from inside the specified folders.” Sounds good!
Step 8: Drag Get Folder Contents into the main area, after (below) Ask for Finder Items.
Look at what happens. The two actions join up in a specific way. An action can have input (data that feeds into it) and output (data that it produces). For one action to succeed another, you usually want the data produced by the first to be fed to the second. The join between the actions in Workflow shows this happening. Ask for Finder Items produces files and folders—the files and folders chosen in the dialog by the user. (In this case, it will produce just one item—a folder—because that’s what you’ll actually choose in the dialog.) Those files and folders are then fed to Get Folder Contents. This works because the output of the first step is the same type of thing as the input to the second step—files and folders.
Tip: This approach to programming is called a dataflow diagram; each step produces data which it passes to the next step, and the steps are represented visually as feeding one step’s output into the next step’s input. Unix programmers are familiar with the same concept through the notion of a pipe .
Step 9: The second step now gets the contents of your chosen folder, but it doesn’t display them. To help with this problem, Automator supplies a special action: View Results. Use the Search field to find it and drag it into the sequence at the end.
Step 10: Now run the workflow again. This time, Automator displays the contents of the chosen folder as a series of Unix paths, inside Automator itself. Having proved to yourself that that the workflow is working, you can click the X at the top right of View Results to remove it from the sequence if you want; but there’s no harm in leaving it there, since its output is the same as its input—it will pass along the folder contents, unchanged.
Step 11: Next, we want to capture the Unix paths produced by the previous step, in a text document. Type
textin the Search field and look through the listed actions. Click each one so you can read about what it does. When you get to New TextEdit Document, bells should go off. It creates a new TextEdit document, and, even more important, it takes text as its input. So evidently it creates a new TextEdit document containing that text . Hmmm, so far, all we’ve produced in our dataflow is “Files/Folders”. What will happen if we follow that with an action whose input is “Text”? Try it and see! Drag New TextFile Document into the sequence as the last step. It joins successfully with the previous step! This shows that what we’ve done is acceptable; Automator will convert the data for us.
Tip: This ability of Automator to convert one type of data into another automatically is important, because it means you don’t have to worry very much about the type of data being handed from one step to the next. If Automator can’t convert one action’s output to the next action’s input, it will refuse to join them, the data types will appear in red, and you’ll know that your sequence isn’t going to work.
Step 12: Run the workflow. (The screenshot below shows the completed workflow.) It works! You choose a folder, and a TextEdit document appears, containing the pathnames of the files and folders within it.
That’s all there is to working with Automator. Every workflow is like this, a straightforward series of actions one after the other. There’s no complicated looping or decision-making.
To learn more, study the example workflows that are included (look under Example Workflows in the Library column), and look over the actions available to you (everything in the Action column). Think of workflows you’d like to create. And, as you use Tiger, ask yourself whether an activity you’re performing or would like to perform could be automated by expressing it as a workflow.
Extra for Experts
If you’re an AppleScript programmer (or you just play one on TV), an Automator action is a terrific way to distribute a script to other users, because it gives those users a little interface for modifying the script’s behavior, and because it lets them incorporate the script into a larger workflow. To get started writing your own Automator actions, see my online article at MacDevCenter.com.