georgeharito.com

A few miscellaneous ramblings of a BMW-loving, Amiga-nostalgic, Mac-using PHP developer from Australia

Menu Close

Combining PDF docs using Automator and Services in Snow Leopard 10.6

UPDATE (10/09/2009): A big thanks to Eric Weijers who pointed out in the comments below that the “Get Finder Items” action that I implemented in this workflow actually doubles up the pages that are in the resulting PDF. If you follow the instructions outlined in the post below, please make sure you don’t add the “Get Finder Items” action.


Before upgrading to Snow Leopard, I had made a few Automator actions that were saved as Finder plugins, and hence were accessible from Finder’s contextual popup window. However, after upgrading to Snow Leopard I found that these Finder plugins were gone (amongst other undesireable, but tolerable and fixable changes). After hearing about Services through the Apple Snow Leopard features page, and podcasts such as MacBreak Weekly, I decided to retool the Automator action as a Service instead.

The cool thing about Services is that it’s been around for ages and no one really used them :) Actually the most cool thing I found about Services is that it’s targetable; you can pick between text services (normal text, URLs, addresses, phone numbers, dates or email addresses) or file services (files, folders, files and folders, documents, image files, PDF files, movie files, audio files or text files) and you can even target in which application the Service can be invoked.

To create a Service, open Automator in your /Applications folder and you will be greeted with the following requestor:

Choose a workflow template

Selecting the Service template will display a blank canvas on which to work from. Note that you can select the target that you need for your Service – for combining PDFs, I selected the drop down values to read “Service receives selected PDF files in any application“.

PDF blank canvas

The action that is central to the whole functionality of combining PDFs is, funnily enough, the Combine PDF Pages action. It is available under the “PDFs” menu in the Library. Drag it over to the blank canvas.

Combine PDFs

The thing that you would need to consider when using this action is what state should the files be when invoking it. Personally, I thought that I would most likely be selecting all the PDFs I want to combine and then invoke the command (either through the Services menu option in the Apple menu, or through the contextual menu).

So to make this work, you need to add the Get Selected Finder Items action – this is available via the Files & Folders menu in the Library. Drag it to the canvas, above the Combine PDF Pages action.

Get Selected Finder Items

I like to have some ability to interact with the Automator action, so I have ticked the Show this action when the workflow runs checkbox under Options.

If you were to run the Automator action right now (select some sample PDFs in Finder and then hit the Run button at the top right corner), you will find in the Result pane for the Combine PDF Pages action a brand new spankin’ PDF file, but named with some random characters and at a location that’s not readily accessible (it’s actually in an OS X temporary folder). This is where you will need to add some more Automator actions to move the file to a more accessible location. You can start by adding the Rename Finder Items action, found under Files & Folders in the Library.

Rename File Automator

We want to change the basename only (the file name, not including the extension), so change the Add Date or Time drop down list to Name Single Item, and enable the Show this action when the workflow runs checkbox under Options to allow you to enter in a name when the Service will be invoked.

When dragging this action into the canvas, you may come across a requestor asking if you want to add another action to copy the file instead. Since the file we want to move is already in a temporary location, and have no interest in keeping it in there, we should select Don’t Add.

Copy Files Automator

Finally, you would want to move the resulting file out of the OS X temporary folder and into a location that’s accessible from the Finder. You will need to drag in the Move Finder Items action (available from the Files & Folders menu in the Library), and turn on the Show this action when the workflow runs checkbox under Options.

Move Finder Items

You can test your workflow by selecting some files in Finder, and then hitting the Run button. You might get a requestor saying that the service cannot receive input while in Automator; just hit OK and continue the test. Once you are happy with the workflow, you can now save it as a Service. Hit the Save As function from the File menu, call it a name (I chose “Combine PDF documents”) and you’re done.

If you select a PDF or a group of PDF files and then right-clicking to invoke the context menu, you will find near the bottom of the menu your new service. It will also be available under the Services menu in the File menu. Note that the service is not exposed to the user if there is a file other than a PDF selected — this is directly controlled by the Services targetting as described above.

Congratulations, you’ve just created your own Snow Leopard Service!

© 2017 georgeharito.com. All rights reserved.

Theme by Anders Norén.