13.4. AutomatorOne of the most touted new features in Mac OS X Tiger is Automator (/Applications). Automator brings the power of scripting to the masses. It's an easy way to automate repetitive tasks that you'd normally have to perform by hand. Using drag-and-drop simplicity, you add various actions to a workflow, crafting the order they are processed to suit the task at hand. Automator ships with a library full of actions. Actions are the individual steps that are processed in a workflow. Each application is responsible for providing actions that perform a function within that app. For example, Apple's Mail includes about a dozen actions that do everything from checking for new mail to sending birthday cards. Not all applications have Automator actions yet, but there are more available each day. To see some of the latest actions, visit Apple's Automator Actions site: http://www.apple.com/downloads/macosx/automator/. 13.4.1. Creating WorkflowsNow that you're a bit more familiar with Automator actions, let's take a look at workflows . Workflows are simply an ordered set of actions. To create a new workflow, select File New. Automator opens a blank workflow, as shown in Figure 13-4. The Automator window is broken up into four main panels. The Library panel lists all of the applications with available actions, as well as some sample workflows and any workflows you might have saved. Selecting an application from the list will filter that app's actions in the Action panel. The Action panel contains the actions available for that particular app, organized by relevancy. As you create workflows, different actions will float to the top as their relevancy increases. Selecting an action causes the description pane to display information about the selected action, such as what it does, what it expects for input, and what kind of output it creates. Figure 13-4. A new Automator workflowThe type of input and output are important, because you should only tie actions together if they use compatible data types. For example, the Finder's "Get Selected Finder Items" action outputs the Files/Folders data type. This data type would work quite well if you connected it to Mail's "Add Attachments to Front Message" action. However, connecting an action such as Address Book's "Get Contact Information" would cause problems. The workflow may not work properly because the actions aren't compatible. Figure 13-5 shows two compatible options (note the input/output markers are connected and are of the type Files/Folders). Figure 13-6 shows two incompatible Automator actions. Figure 13-5. Compatible Automator actionsFigure 13-6. Incompatible Automator actionsFinally, the empty gray panel along the right is where you build your workflow. To build a workflow, start by dragging an action from the Action panel and dropping it into the workflow area. As an example, let's create a workflow that will send birthday greetings to our friends.
First, select Address Book from the Library panel. Next, drag the action named "Find People with Birthdays" out of the Action panel and drop it in the workflow area. Then, select Mail from the Library panel and track down the "Send Birthday Greetings" action. Drag the action out and drop it below the "Find People with Birthdays" action in the workflow area. At this point, you have the bare necessities for an Automator workflow. You might want to tweak it a bit and make it more personal. Most actions allow you to configure certain aspects of their operation. In the case of the "Find People with Birthdays" action, you can select whether you want to search for anyone whose birthday is Today, Tomorrow, This Month, etc. For the "Send Birthday Greetings" action, you can customize the greeting text and the birthday image that's sent with the message. Once you've played with the settings a bit and settled on a message, the resulting workflow looks something like Figure 13-7. Figure 13-7. The Birthday Greetings workflowTo execute your new workflow, click the Run button. Automator will process each step of the workflow and, if anyone in your Address Book has a birthday coming up, send out some mail messages. Assuming you don't have any problems and you're happy with the flow of the workflow, you can save the workflow for later use. For extra convenience, you can create a repeating iCal event that runs your Birthday Greetings workflow every week to send out the messages for you. See the section "Using iCal to Schedule Tasks. earlier in this chapter, for more information. 13.4.2. Running WorkflowsThere are many different ways to run your workflows. You can have them run by iCal on a scheduled basis. You can add them to your Script menu by saving them in ~/Library/Scripts. Workflows can be saved as double-clickable applications. You can even attach them to folders and use them as folder actions. The folder actions option is particularly powerful. Using folder actions, you tie an Automator workflow to a particular folder. Any files that are placed in that folder are then processed by your workflow. Let's take a look at setting up a folder action workflow. This particular workflow can be used to make thumbnails of image files that are copied to the folder. First, create a new workflow by selecting File New. The first action you want to use is the Finders "Rename Finder Items" action. Configure the action so that it adds the text _thumb to the end of each file's name. Next, add Preview's "Scale Image" action. Select whether you want Preview to scale each image to a specific size or based on a percentage, as well as the desired size or percentage. The resulting workflow is shown in Figure 13-8. Figure 13-8. The Thumbnailer workflowHere comes the tricky part. Save the workflow by selecting File Save as Plug-In. Give the workflow a name, like "Thumbnailer," and then select Folder Actions from the "Plug-in For pop-up. Next, use the "Attached to Folder" pop-up to choose the folder you want to use for processing the thumbnails (e.g., create a new folder named Thumbnailer in the Pictures folder of your Home directory and attach the action to that). Finally, click Save to put everything into place. Now when you drag an image file into your new Thumbnailer folder, the file will be renamed and resized to your specified dimensions. Just remember to copy the file to the folder instead of moving it. Otherwise, you'll lose the original full-scale file. 13.4.3. PDF ServicesAnother way to use Automator workflows is with Mac OS X's PDF Services. PDF Services are a convenient way of using Adobe's Portable Document Format (PDF) to create print-ready documents from within any application. The PDF menu found on Mac OS X's print dialog gives easy access to a variety of workflows for creating PDFs. You can find out more about PDF Servicesand printing in generalin Chapter 10. As discussed in Chapter 10, Apple has included several Automator workflows for use with PDF Services. You can take a look at these workflows yourself by looking in the /Library/PDF Services folder. Figure 13-9 is of one of Apple's included workflows: Compress PDF. Figure 13-9. The Compress PDF workflowAs you can see, most of the PDF-oriented workflows included with Mac OS X are rather simple. The only thing that makes a PDF Service workflow different from any other is that it's geared toward PDFs and is kept in the PDF Services folder (either /Library/PDF Services or ~/Library/PDF Services). When you save a PDF workflow, use the Save as Plug-In option and select Print Workflow as the plug-in type. Figure 13-10 and Figure 13-11 show PDF workflows that you can create and use yourself. Figure 13-10. The Grayscale PDF workflow |