Use Mac OS X Automator and Services To Speed Up Repetitive Tasks

“Automator”:automator is one of best kept secrets in Mac OS X. It’s kind of like drag-and-drop scripting that lets you create workflows to automate and speed up repetitive tasks. In Snow Leopard, you can use Automator to create your own services that are accessible via the Services menu and can also be contextual, showing up when you right-click on an item like text selections or files and folders.

The Automator application lets you build a workflow by choosing from a collection of actions, some native to OS X, some installed by other applications, and dragging those actions into a workflow. There are actions that perform standalone tasks like copying a file to a specific folder, processing an image, or asking for input. If you need something more advanced there are actions that let you run shell commands, or even call other scripting languages like Python, Perl, or Apple’s own AppleScript. Combining these actions into a workflow lets you automate just about anything.

Addressing an Envelope Using Selected Text
I recently received a request to mail some additional information for a rebate I submitted several weeks ago. The email message contained the mailing address for the fulfillment center. Ordinarily, this means either hand addressing an envelope or going through several steps to launch Pages, choose a template, cut and paste the address, and print the envelope. It felt like I should be able to select the address and have an envelope automatically prepared and ready to print, but there is no built in way to do this.

Using Automator, I created a service that appears as a contextual menu item when working with selected text… in this case an address. In this workflow the Automator service is essentially a wrapper around AppleScript which does the heavy lifting here.

Automator envelope workflow

Here is the AppleScript that makes it happen.

on run {input, parameters}
	-- set the name of Envelope template to use
	set theTemplate to "Classic Envelope"
	-- set selection to first item of input list, ignore rest
	set theSelection to item 1 of input as text
	tell application "Pages"
		-- launch Pages without "Template Chooser"
			make new document with properties {template name:theTemplate}
		on error
			-- display msg if the template does not exist
			display alert ¬
				"Template does not exist or
the document could not be created" buttons {"Cancel", "OK"} as warning
			-- If can't create document, then bail out of the whole shebang!
			quit application "Pages"
		end try
		tell the front document
			--delete the default template text and make a new paragraph
			delete every paragraph
			make new paragraph at beginning
			tell body text
				-- put the selected text into the new paragraph
				set paragraph 1 to theSelection
			end tell
		end tell
		-- open the print dialog ready to print! Enclose in try block to ignore errors
			print the front document with print dialog
		end try
	end tell
	return input
end run

Download All Links on a Web Page
There is a great add-on for “Firefox”:ff called “DownThemAll”:dta that lets you download all the links on a web page without the need to click on each link individually. I have not been able to find anything like it for Safari. I wanted to download several zip archives containing sample code for a tutorial I was working through and was certain this could be done using Automator. In just a few minutes I hacked together a workflow that finds links on the current Safari page, filters them by extension, and displays a list for me to select from, before downloading the links to the Downloads folder. This workflow makes use of several Safari specific actions.

Automator download all workflow

Copy or Move Files and Folders to iTunes
One of the easiest ways to add songs to iTunes is by copying audio files or folders containing songs to the aptly named Automatically Add to iTunes folder. While this is relatively easy, why not save a few mouse clicks and drags by adding a service to the contextual menu for Finder items like files and folders. Add one service to copy files or folders, and a second to move them.

Automator copy to iTunes workflow

I have services that copy and move files to my “Dropbox”:db folder, create tar archives from selected files and folders, and even automatically shorten a selected URL with “”:bitly. Automator includes actions for working with text files, creating PDF documents, and even processing images. There is really no limit to the cool things you can do with Automator.

There are lots of great places online where you can find workflows. The best place to start is at “Mac OS X Automation”:osxautomation where you will not only find sample services, but some great tutorials about Automator and AppleScript.

Using Automator to build workflows is simple and takes little time to learn. Services are an effective way to automate repetitive tasks that save time. Make your computer work for you now by creating a few services of your own.