5 Automator workflows everyone should have

I meet a lot of people with Automator anxiety: they think using OS X’s built-in workflow-maker is a lot more complex than it really is. The truth is that Automator workflows are (a) pretty simple to assemble and (b) great for simple but repetitive tasks that you do all the time anyway.

To show you what I mean here are five workflows that I think pretty much every Mac user should have. They do things we all need to do: Wrap text in quotation marks, for example, or count the number of words in a selection of text. There might be other ways of doing the same things, but Automator is built into your Mac and you can implement them yourself for free in a couple of minutes.

Wrap text in quotes

This one works with selected text to wrap it in quotation marks.

To start, create a new Automator Service workflow and configure its header area to process selected text in any application. Click the Output Replaces Selected Text checkbox so the result of the workflow—the wrapped text—will be inserted in place of your selection.

Although Automator includes a number of actions for working with text, it doesn’t have one for adding a prefix or a suffix. As a workaround, you’ll need to use AppleScript for this. So, add the Run AppleScript action to the workflow, and copy-and-paste in the following script, which simply adds quotation marks around any text input it receives:

on run {input, parameters}
return "\"" & (input as string) & "\""
end run

Save the finished workflow as Text > Wrap in Quotes and you’re done.

The next time you’re ready to wrap some text in quotation marks, just Control- or right-click the selection and choose Text > Wrap in Quotes. (You could also choose the workflow from the Application > Services menu.)

Count words of selected text

Another one for working with selected text, this one gives you a quick word count.

Create a new Automator Service workflow and set it to process selected text in any application. Leave the Output Replaces Selected Text checkbox unchecked.

Automator doesn’t have any built-in actions for counting words. So, again, you’ll have to add the Run AppleScript action to the workflow, and enter the following:

on run {input, parameters}
set theWordCount to count words of (input as string)
display dialog (theWordCount & " words in the selected text." as string)
end run

Save the workflow as Text > Display Word Count. Next time you want to know the length of some text, just select it and run the workflow from the Services menu.

Create subfolder

Although it would be super useful, OS X still lacks a handy Add Subfolder command in the Finder. Sure, you can open a folder first, and then create another folder inside of it, but that’s one more step than necessary.

Create a new Automator Service workflow and set it to process folders in Finder.

Find the Set Value of Variable action and add it to the workflow. Then, from its popup menu, create a new variable and name it Folder.

After that, add the New Folder action to the workflow. Enter a name of Subfolder or whatever else you prefer. Drag the folder variable from the Variable area at the bottom of the workflow to the Where popup. Finally, with the action selected, choose Action > Ignore Input from the menu bar. This is important because the New Folder action copies anything it receives as input into the new folder, and you don’t want this to happen. By setting the action to ignore its input, you bypass this behavior.

Save the workflow as Folder > Create Subfolder. The workflow should now appear under Services in the Finder’s contextual menu when you Control or right-click on a folder. Just select a folder and then the service.

Add date to files

This one adds a current date prefix to the names of any selected files or folders.

Create a new Automator Service workflow and set it to process files or folders in Finder. Find the Rename Finder Items action and drag it to the workflow. If Automator prompts you to insert a Copy Finder Items action first to preserve your originals, click Don’t Add; you’re just adding a prefix to the names of the files, not deleting them or anything serious like that.

Configure the action to Add Date or Time. Then set the Date/Time popup to Current, the Format popup to Year Month Day, the Where popup to Before name, the first Separator popup to Dash, the second Separator popup to Space, and click the Use Leading Zeros checkbox. While all of this sounds kind of complicated, it’s really just telling Automator you want the date prefix in YYYY-MM-DD format.

Lastly, save the workflow as Files and Folder > Add Date Prefix. Your workflow now shows up in the Finder’s Services menu when you Control- or right-click on something. Select a file or folder, then select the service, and the date will be prepended.

Toggle hidden files

Sometimes it helps to see hidden system files; this one toggles their visibility on and off.

Start by creating a new Automator Application workflow. Automator doesn’t have an action for toggling on and off the visibility of hidden files, so again you’ll need to use AppleScript to do it. Actually, this AppleScript really just triggers a bunch of Unix commands to update the Finder’s preferences to show hidden files and then relaunch the Finder. Add the Run AppleScript action to your workflow, and enter the following:

(When you copy and paste, make sure that the first line, beginning "if" and ending "then", and the sixth, beginning "do" and ending "as string" are each a single line, with no hard returns in the middle.) Just save the workflow as Finder > Toggle Hidden Files. That done, if you double-click that app, your Finder will disappear for a second, then reappear with hidden files showing or hidden (depending on their state before you launched the app). (And be careful with those hidden files: They usually do important stuff, and deleting or renaming them could get you into trouble.)

Ben Waldie , Macworld

Ben Waldie is president of Automated Workflows, LLC, a company offering AppleScript, Automator, workflow, and productivity consulting services to Mac-based businesses. He is also the author of Automator for Mac OS X: Visual QuickStart Guide (Peachpit Press, 2008) and AppleScripting the Finder (Automated Workflows, LLC).More by Ben Waldie