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:
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“.
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.
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.
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.
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.
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.
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!
Eric Weijers says:
I use this kind of workflow a lot.
In OS X 10.5 the files were passed in the order they were selected in the finder.
In OS X 10.6 it looks like they are passed in the order they appear in the finder.
I now have no control over the order the PDF’s are merged…..
Do you have the same experience?
Eric Weijers
September 9, 2009 — 4:06 pm
georgeharito says:
Hi Eric,
I can’t say I used a workflow like this in 10.5. I had some workflows set up that would process a whole lot of images (eg. making thumbnails), but haven’t had it do something like this before (like combining files).
It’s a real shame because Automator unlocks so much power in OS X, but it’s these issues that prevents it from realising its true potential. These issues really make or break the functionality that Automator offers.
Having said that, another issue happens to me. Actually I have a slightly different issue — the PDFs get combined twice. For example, if I had a file called page1.pdf and another called page2.pdf, the resulting PDF from this workflow will actually have 4 pages: page1, page2, page1, page2. I can’t find a fix for this and although I tried to report it to Apple as a bug, their bug reporting tools have bugs (oh the irony!) so I can’t log in and flag the issue to them.
Here’s hoping it’s fixed in 10.6.1.
September 9, 2009 — 5:18 pm
Eric Weijers says:
You should leave out the Get Selected Finder Items action. By using that action you get the files in twice. The files are already passed by selecting them in the finder and running the service…
I hope apple will fix the selecting problem. Workes just fine in 10.5…..
Eric Weijers
September 9, 2009 — 11:49 pm
georgeharito says:
Hi Eric,
Thanks for that! I’m at work at the moment, I’ll test it when I get home and update the blog post accordingly.
This issue of mine was driving me nuts, thanks for pointing out the mistake.
georgeharito
September 10, 2009 — 2:21 pm
Don Montalvo says:
Is there a way to toss up a window allowing you to sort the pages before combining into a single PDF?
Also, is there a way to combine other formats as well (JPG, etc.)?
Thanks,
Don
October 22, 2009 — 8:49 am
georgeharito says:
Hi Don,
As far as I know, there isn’t any facility in Automator to display an interface so that you can custom sort the PDF pages. I can only find the Combine PDF action in Automator, which won’t accept any other files other than PDF, sorry.
October 22, 2009 — 10:59 am
Don Montalvo says:
Theres a “New PDF from images” that lists PDF as an input format.
Don
October 26, 2009 — 12:46 pm