Discovering Automator by Hanaan Rosenthal • Automator, A Mac OS X Tiger automation app for the rest of us
 
 
Chapter 9: Creating Automator Plug-Ins for Other Applications
One unique way to use and distribute actions is by saving them as plug-ins. Plug-ins are not for use with Automator, but rather little programs you create with Automator that can enhance other applications. Plug-ins you create with Automator can be used with applications such as the Finder, iCal, and Image Capture. Workflows can also become available for use as Folder Actions or available through the Script Menu.
In general, plug-ins are just workflows. For the most part, all plug-ins are created in the same manner: You choose Save As Plug-in from the File Manu, specify the type of plug-in you want to create, name the plug-in, and click Save.
Figure 1 shows the Save As Plug-in dialogue box, and Figure 2 shows the options in the Plug-in For popup menu found in that dialogue.
 
Figure 1. The Save As Plug-in dialog box.
 
Figure 2. The Plug-in For popup menu
Plug-ins you can create with Automator
As you can see in Figure 2, there are currently six different types of plug-ins you can create with Automator. Below is a short description of every type of pi. Later in the chapter you will be able to create your own plug-ins for some of the types mentioned here.
Finder plug-ins: A Finder plug-in is a workflow that can be executed by selecting it from the Finder’s contextual menu. The finder item clicked when the workflow is selected is passed as input to the first action.
Folder Action plug-ins: A Folder Action plug-in is a workflow saved as a folder action. It can be attached to a folder and activated when a file or folder is added to that folder. The added files/folders will be the input of the first action.
iCal Alarm plug-ins: An iCal plug-in is a workflow that can be used as an iCal alarm. When the event the alarm is assigned to is due, then the workflow executes.
Chapter 3 explains how to save and use an iCal alarm plug-in. Refer to that chapter for details.
Image Capture plug-ins: An Image Capture plug-in will be available in the list of applications that can process photos after they are downloaded with the Image Capture application.
Print Workflow plug-ins: A Print Workflow plug-in is a plug-in that can be executed as part of a PDF creation process from the Print dialogue box. You use this process if you want to execute a process on a PDF file right after it is created using the Print command. The created PDF file is passed to the first action in the workflow as input.
Script Menu plug-ins: A Script Menu plug-in is a workflow that is executed when it’s picked from the Script menu in the menu bar.
Where do the plug-in workflows live?
When you save a workflow as a plug-in, it is saved in a special place in the system which allows the plug-in to be user by the specific utility or application.
The table below shows the different plug-ins you can create, and where on your Mac the file is stored.
Plug-in
Saved in folder
Finder
User/Library/Workflows/Finder/
Folder Action
User/Library/Workflows/Folder Actions/
iCal Alarm
User/Library/Workflows/iCal/
Image Capture
User/Library/Workflows/Image Capture/
Print Workflow
User/Library/Scripts/
Script Menu
User/Library/PDF Services/
Finder plug-ins
As Figure 3 shows, workflows saved as Finder plug-ins are executed when they are selected from the Automator sub-menu from the Finder’s contextual menu.
What makes the Finder plug-ins a bit different from other workflows is that the input of the first action in workflows that handle files usually defines the file or folder that the action is going to work on. But since Finder plug-ins are executed when you control-click on a file or folder, that file or folder is what’s passed to the first action as input. This fact alone makes the Finder plug-ins feature into an awfully useful way to add functionality to the Finder.
In Figure 3 you can see that the workflow named “Back up and archive files” workflow has been saved as a Finder plug-in. That means that the user can now control-click (or right-click) on any file or folder, choose this workflow, and have that file or folder archived and backed-up.
 
Figure 3. The contextual menu shows the workflows saved as Finder plug-ins.
Creating a Finder plug-in
The Finder plug-in workflow you will create will allow you to control-click on a file or folder and attach it to a new Mail message. This workflow is going to be very simple. In fact, it will have one action only: The New Mail Message action.
The neat thing about this action is that when you pass it a file or folder as input, it attaches that file or folder to the new Mail message it creates.
1.    Create a new workflow.
2.    Add the “New Mail Message” action.
3.    Enable “Show Action When Run”
Click the “Options” disclosure triangle at the bottom and check the “Show Action When Run” checkbox.
When done, your workflow will look like the one in Figure 4.
 
Figure 4. The sole action in the ‘New Message with This File Attached’ action.
4.    Save the workflow as a Finder plug-in.
Choose Save As Plug-in from the File menu. Fill the dialog box like the one in Figure 5.
 
Figure 5. Saving our Finder Plug-in.
Now that the plug-in is saved, you can use it. Control-Click on the file you want to send, as shown in Figure 6, and choose Automator -> Attach this file to new message.
 
Figure 6. This screen shot shows me attaching a chapter of this book before I email it to Chuck, my beloved editor.
Creating a Folder Action Plug-in
The workflow you’re about to create will also have a single action. The workflow will take any image file that is added to a folder on the desktop and add this image to iPhoto. Actually, it will take any file you drop in it, which leaves it up to the user to only drop iPhoto-compatible files.
1.    Create a new workflow.
2.    Add the Import Photos into iPhoto action.
After adding the action, expand the Options disclosure-triangle, and check the Show Action When Run check box. See figure 7 for example.
 
Figure 7. The “Import Photos into iPhoto” action, the only action in this workflow.
The “Show Action When Run” feature is used to allow the user to pick the album for the photo, and to specify if to erase the image file after importing.
3.    Save the workflow as Folder Action Plug-in.
When saving a workflow as a folder action plug-in, you also have to specify what folder you want the folder action attached to. Before proceeding, you have to create this folder.
So, create a folder on the desktop and call it “Drop images for iPhoto.”
Once the folder has been created, choose Save as Plug-in from the File menu. Figure 8 shows the dialogue box the way it should be setup.
 
Figure 8. Save the workflow as a Folder Action plug-in.
Notice that the popup menu “Attached to Folder” has the folder we created on the desktop specified. To do that, choose “Other” from that popup menu and navigate to the folder on the desktop.
After the plug-in has been saved, drop an image file into the “Attached to Folder” folder on the desktop. The workflow you created will be executed, and the image will be added to iPhoto.
So cool, I can barely hold it in.
iCal alarm script
 
Print Workflow Plug-in
One of the cool things about OS X is the ease in which you can create a PDF: Simply print the job, and click Create PDF right in the Print dialogue box. It Tiger, this feature was taken to a new height when the Create PDF button was transformed into a popup button that includes several commands such as Fax PDF, Save as Postscript, and more.
With Automator, you can create plug-ins that can be also executed from the PDF menu in the Print dialogue box. The beauty of this feature is that after the workflow is selected from the PDF popup menu, the PDF is created, and a reference to the PDF file is passed to the first action in the workflow.
This allows you to create workflows that process pdf files, and then place these workflows right in the Print menu for people to use. Say, for instance, that you have to save an invoice as PDF, then email it to a couple of people and make copies of it to a few locations of the hard disk. You can make a workflow that does that, call it “PDF and process Invoice,” and add it to the Print dialogue box. Figure 9 shows the PDF button with this command attached to it.
 
Figure 9. A Print Workflow plug-in can be selected from the PDF menu in the Print dialog box.
Reference to file!? What is this, a bibliography?
I use the term “Reference to file” because the file itself isn’t passed to the Automator action, only a reference to it.
Automator tells the action this: “Take the file is such and such folder and process it.”
Nowhere is the file being copied or moved.
The Print Workflow plug-in you will create will take the PDF that is created by the PDF button and print it. This way the user can ask for a hard copy and a PDF at the same time. You can even have a couple of these made: one for the laser printer and one for the color ink jet. This way you can name one of the workflows “PDF and print in B/W” and the other, “PDF and print in color.”
1.    Start a new workflow.
2.    Add the “Print Finder Items” action.
From the “Print to” popup, choose your color printer. (If you have none connected, no big deal; leave as “Default Printer” and pretend you did.)
3.    Choose “Save as Plug-in” from the File Menu.
4.    Choose “Print Workflow” from the Plug-in for popup and type “PDF and print in color,” as shown in Figure 10.
 
Figure 10. Save the workflow as a Print Workflow Plug-in.
To use the workflow, choose Print from any application.
In the Print dialogue box, click the PDF button and choose the workflow plug-in you’ve just created: “PDF and print in color.”
The document should be printed to a PDF file and to the printer you chose.
Folks, this looks like it!
You have just completed the final chapter of the book. M… M… I know you feel like doing it all over again!
Seriously, I do hope you enjoyed the book and that the balance of beginner/advanced stuff was just right. While there can’t be one book that will hit the spot for everyone, we tried to create a book that hits some spot for most.
The next section of the book has some information on how to get more Automator actions. Fresh actions are written all the time by developers such as myself, so go ahead and learn how to get make them your own (many of them are free!).