Chapter 8: Workflow Ideas
So far the focus of the book was on showing you different features of Automator and explaining how they work. This chapter is different. Here, I will show various cool workflows you can use Automator to create.
Window cleanup workflow
It seems like everyone has their favorite way of displaying a window in the Finder: Some like icons, some like lists or outline views. Personally, I like them all to be the same so that when I open folders in folders, some are icons, some have different size icons, and some are lists, etc.
The following workflow will take one top folder, such as the startup disk, and change the views of all folders inside that folder (and including that folder), to the settings you determine in the action interface.
The workflow is simple and can include two or three actions, one being optional.
1. Add the folder you want to start with.
This time, I want you to control-click that folder, and choose Automator Create Workflow.
The folder will be added to the start of a new workflow in the “Specify Finder Items” action.
Start by testing the workflow on a folder with maybe a few nested folders. Do not start with your main hard drive!
2. Optionally, add the “Launch Application” action.
Strictly for the entertainment value; it’s fun watching the Finder windows fly at the speed of light as Automator changes their view settings.
3. Add the “Set Folder Views” action.
This action is the star of the workflow. Make sure to check the “Apply Changes to Sub-folders” checkbox. This will make the change affect all nested folders, not just the folder you selected.
Change the settings in the interface to match how you want the windows to open. Start by selecting the view type from the top left popup menu, and then specify the rest of the settings.
If you want to change window properties as well, such as toolbar and sidebar options, then check the “Apply window properties” checkbox and make your choices in the box underneath it.
Once done, and your workflow looks something similar to the one in Figure 1, then run your workflow to see what happens.
Figure 1. The “Windows Washer” workflow.
Downloading images from a web site
The following workflow is so powerful, if you’re not careful it could take three days to run and fill an entire 200 GB hard disk.
This workflow will go to a web page, look at all the links in that page, go to each linked page, and download all of the images from this page to a folder you specify.
Not only that, but instead of just going one level, you can dig deeper and download all the images in the pages linked to the linked pages. My testing on the Apple.com/Start page, there were almost 4000 pages linked to the pages linked directly to this page. If I continued the process I could have ended up with tens of thousands of little gif images…
Anyway, here’s how you do that:
1. Start with the top web page.
Add the “Get Current Web Page from Safari” action, or the “Get Specified URLs” action. Either one will do, the latter will allow you to specify more than one URL.
This top URL will be the entry point of the workflow.
2. Get the links from that top URL.
Add the “Get Link URLs from Webpages” action. This will send all the URL links from your starting page to the next action.
Now, this is where you can explode the thing. You can actually add multiple instances of this last action. Each instance will take all of the links from the previous instance and return all of the links on all of these pages. Adding two or three instances can yield tens of thousands of pages, making the workflow take forever.
You can also opt to not have any instance of this action, only downloading the images from the top web page.
You can curb the amount of webpages by clicking the “Only return URLs in the same domain as the starting page” checkbox. This will keep you confined to the domain name of the original page, not going to other domains.
3. Next you will get the image URLs from these links.
Add the “Get Image URLs from Webpages” action. This action will pass on URLs to all the images on the URLs passed to it as input. Also here, if the previous action passed, say, 100 links to this action, and there are 20-30 images per page, then you’re looking at a few thousand images.
4. Finally, download the images.
Add the Download URLs action.
When completed, the workflow will look like the one in Figure 2.
Figure 2. The finished “Image Download Robot” workflow.
Heard the news?
In the next workflow you’re going to combine web actions with sound actions.
The workflow will go to your chosen news site, get the text from it, save the text as spoken sound, and upload that to your iPod.
You will most likely want to find a news source or other type of page that has the smallest amount of links and extraneous information. RSS feeds may work well.
Then, you can take the news around with you. Here’s one way to get it done:
1. Start with the page you want to ‘listen’ to.
Add the “Get Specified URLs” action and specify the URL of the web page you want to listen to.
2. Get that page’s text
Add the ‘Get Text From Webpage’ action
3. Save the text to a sound file
Add the ‘Text to Audio File’ action. Specify the voice you want to have the news read to you, and save it to the desktop under the name “News Download.aiff”. Later on this file will have top be deleted.
4. Import the file to iTunes and add to your iPod.
Add the action “Import Audio Files.” Use the MP3 encoder since sound quality is not an issue here.
After that, add the “Add Songs to iPod” action.
When done, connect your iPod and run the workflow. If no ipod, click this link and buy one: store.apple.com/.
The finished workflow should look like the one in figure 3.
Figure 3. The finished ‘News to go’ workflow.
A photographer special
As photographers among us know, photographers love taking pictures, and love adjusting them in PhotoShop (the few that are not absolutely perfect to begin with, of course). Anything in between, such as copying, converting, and renaming large masses of files, is not anyone’s cup of tea.
The raw material going into the first action of the workflow can be a few things. The first action can be the “Download Pictures” action. This will download the pictures and send them to the following action for processing. You can also create a workflow that will start after the pictures have been downloaded, and then the first action will be either the “Specify Finder Items” action or maybe the “Get Specified iPhoto Items” action.
Any way you look at it, this workflow must have a bunch of pictures going into it.
It may be a good idea to separate the job into two workflows: One that downloads the pictures, and one that processes them. This way, you can have different processing workflows and match the appropriate one with the workflow that downloads the pictures.
Figure 4 shows the workflows and how they can be mixed and matched.
Figure 4. The chart shows the workflow with the possibility of different actions used to kick it off.
In the example workflow below:
This workflow will take some of these actions and turn them into a workflow. While it won’t be exactly what you need, it’s a starting point.
The first order of the day is to create the folders you will need for the downloaded pictures. The action will create a single folder named “Pix Download” on the desktop, and in that folder it will create two other folders: “Raw Images” and “Processed Images.” The name of the main folder will have the date tacked onto it when the workflow concludes. The name of the main folder can’t be changed at the start since you need to know what the name is throughout the workflow, and once it is renamed, you can’t get back to it later on using the old name.
The three actions below will create the folders needed for the workflow.
Actually, the only way to add these three actions is to add the first one which will create the top folder, run the workflow, and then add the other two. The reason for doing that is that after you run the workflow, the folder “Pix Download” folder will be available and you will be able to specify it as the containing folder for the other two folders.
Of course, you can always create the folder structure manually, but you risk mistyping a folder name.
You will also need to run the workflow right after adding the “New Folder” actions. This will actually create the folder for you, allowing you to specify them later in the workflow using the “Get Specified Finder Items” action.
After adding these actions, collapse them as a space-saving measure.
Figure 5. The first part of the “Photographer” workflow.
This part creates the folders needed for the workflow.
Using results
The New Folder action can work in two ways. If nothing appropriate is passed to it from the previous action it will create an empty folder. However, if the previous action’s result is a reference to files or folders, then these will be copied to the new folder.
This should be considered carefully since you should only allow it to use the previous action’s result if you want to copy to the new folder the files passed to it.
In this case, we really don’t. If we allow the second and third New Folder action to use the result, it will actually copy its containing folder into it, including itself. This will go on multiple times until some arbitrary barrier is reached, leaving you with the first and second folders nested in each other hundreds of times.
To resolve this situation, you have to choose “Ignore Result from Previous Action,” as shown in Figure 6.
Figure 6. The popup menu allows you to ignore result of previous action.
Getting the raw images
The next step in the workflow will be to get the raw images to the correct folder. We can have the workflow move them there rather than copy them since we’re not planning on manipulating the images in that folder. After the images are moved we will have the workflow rename them with a serial number and a date.
The following step after that is to copy the items to the “Modified Images” folder.
We will use the “Download Pictures” action to start.
Actions 4 through 7 shown in move the pictures to the Raw Images folder and renames them. Notice that there are two version of the “Rename Finder Items” action: One replaces the name with a new name and a sequential serial number, and the other tacks-on the date to the end of the name.
Figure 7. Actions 4 through 7 above make up the second portion of the “Photographer” workflow.
Shortcut: To duplicate an action that already exists in your workflow, option-drag the title bar of that action to the new location.
Get down to processing
After the raw files have been renamed, the next step is to copy them to the “Modified Images” folder. This is done with the “Copy Finder Items” action.
Add the “Copy Finder Items” action to the end of the workflow and specify the “Modified Images” folder as the destination, as shown in Figure 8-.
Figure 8. The ‘Copy Finder Items’ action that copies the raw images to the modified images folder.
At this point, we have taken care of moving, copying, and renaming all the images. This is the time that we can start paying attention to the actual processing of the images.
There are many things you can do to images with Automator. Apply a ColorSync profile, resize, convert file formats, and more. Some of these functions are better done with Photoshop, where you have probably done them so far, and would rather continue doing so.
One of the cool actions you will find is the action that executes a Photoshop Action. Incorporating this action in your workflow will allow you to incorporate any of your existing Photoshop actions into your workflow.
Rename Finder Item
One of the first things I noticed about the Finder actions that came with Automator is that while the action that renames Finder items was really cool and sophisticated, it lacked a small feature: it can’t simply replace the name of a file or folder with another name.
What I did is create my own action and post it on automatoractions.com. It is called Rename Finder Item, rather then Rename Finder Items, used by the Finder.
Although I used Xcode to create the action, the functionality of the action is but a few lines of AppleScript. Here’s the script for the Run AppleScript action:
on run {input, parameters}
-- Change the following line with the name you want
set new_name to "downloadmovies.scpt"
set the_file to item 1 of input
tell application "Finder"
set name of the_file to new_name
set the_result to (container of the_file as string) & new_name
end tell
return {alias the_result}
end run
Line 2 of the actual code, which starts with “set new_name to…” can be altered to include the actual name you want to give the file.
Simply pass a file or folder to this action, shown complete in Figure 9, and run.
Figure 9. The “Rename File” action/workflow.