How To Combine PDF Files in Mac OS X Using Automator To Make A Service

How To Combine PDF Files in Mac OS X Using Automator To Make A Service

Many scanners let you choose between scanning one-PDF-per-page or scanning all the pages into one big PDF. The scanner I use does.

However, what happens when you have multiple PDFs that really should go in one document? How do you combine PDFs together?

There are a million ways to do this, including some I have talked about before like using Preview.app to drag and drop pages, and there are lots of applications that one can use to combine PDFs, but I wanted to do something that would be:

  • Already built into the OS and not require any additional software.
  • Easy to use.
  • Repeatable so I only have to set it up once and can use it again and again.

We’re going to use a Mac OS X tool called Automator to set this up. If you have seen my How to Split PDFs tutorial, this is basically the reverse.

Start Automator

In Finder, go to Applications and then start Automator.

Choose Service

In the window that pops up, highlight Service and then hit Choose.

Automator Choose Service
Automator Choose Service

Set The Variable For The Original PDFs

At the top of the window at the right, change the Service receives selected dropdown to PDF files. I set the in dropdown to Finder.app. I haven’t tested it in other applications.

Now in the Library section on the left, click on Utilities and then find Set Value of Variable. Drag it to the main window on the right.

Drag Automator

In the Variable dropdown, choose New variable… and call it originalPDFs.

Here’s what the first rule looks like so far.

Automator Get Variable

Set The Variable For The Path Of The PDF

We are doing this step because of a weird way Automator works. It doesn’t make it easy to save the resulting PDF to the same folder as the original.

I could prompt the user to choose a path, but I wanted to make it automatic so we have to get a bit geeky.

Note: if you’re an Automator expert and know a better way to do this, please leave a comment!

Still in the Utilities section of the Library on the left, find Run AppleScript. Drag it to the main window under our last step.

In the Run AppleScript window, paste in this code:


on run {input, parameters}
set pathList to {}
repeat with itemNum from 1 to count of input
tell application "System Events"
copy POSIX path of (container of (item itemNum of input)) to end of pathList
end tell
end repeat
return pathList
end run

(Basically that is going through the PDFs that you are splitting and copying the folders that they are stored in.)

Now in the Utilities section of the Library, find our old friend Set Value of Variable and (you guessed it) drag it into the main window under our last step.

In the Variable dropdown, choose New Variable… and give your new variable a name of containerPath.

Here’s what these steps look like:

Automator Get Path

Combine The PDFs

Now it’s time to do the combining!

First, we want to get the list of PDFs that we had saved back in the first step.

In Library -> Utilities, drag Get Value of Variable to the main window under our last step.

In the Variable dropdown, choose originalPDFs.

Right under the Variable dropdown there is an Options button. Hit that and check Ignore this action’s input.

Now in Library on the right, choose PDFs. Find Combine PDF Pages and drag it under the last step.

Next, in Library on the right, choose Files & Folders. Find Rename Finder Items and drag it under the last step. It will pop up a message asking you if you want to preserve an extra copy. We don’t need that, so hit Don’t Add.

In the Rename Finder Items box, change the dropdown to Name Single Item. Then hit the Options button and check Show this action when the workflow runs. This will let name the new PDF.

Next, also in Files & Folders, drag Move Finder Items under the last step. In the Variable window at the bottom of your screen, find your containerPath variable. Drag it up on top of the To dropdown.

Here is what those last steps look like:

Combine PDFs
Combine PDFs

Save The Service

Alright! You’re done! Here’s the entire rule (click to see it bigger):

Mac Combine Service

Go to File > Save and give your new service a name. I’ll call mine Combine PDFs.

Use The Combine PDFs Service

You have just created a Service. This means that if you right-click a group of PDFs in the Finder, you can combine them right from there. Let’s try it.

Find a group of PDFs on your Mac, highlight them, and right-click. Choose the Services menu near the bottom. If all went well, you should see Combine PDFs (or whatever you called your Service) in the list. Choose it.

Combine Mac Service Right-Click
Combine Mac Service Right-Click

It will think for a moment and then pop up a box where you can give the new PDF a name. I just called mine “Combined”.

Combine Mac PDF Give Name
Combine Mac PDF Give Name

Boom. I now have a PDF called Combined.pdf that contains all the selected PDFs.

Mac PDF Combined
Mac PDF Combined

Best of all, since I went through this trouble to set it up as a Service, going forward whenever I need to combine PDFs, I just have to right-click on them.

Downloading The Service

If you don’t want to go through the hassle of setting this all up, you are welcome to use mine.

To use it, download the file to your computer and double-click it to Unzip it.

You want to move the file to the ~/Library/Services folder. It’s probably hidden for you, so the easiest way to get there is:

  • Go to a Finder window
  • Choose the Go menu and then Go to Folder…
  • Type or paste in ~/Library/Services

Once that window opens up, drag the CombinePDF.workflow file there.

Click Here To Download CombinePDF20.zip

This article was originally written in August 2010. It was updated in September 2015 for OS X Yosemite and to improve the workflow.

About the Author

Brooks Duncan helps individuals and small businesses go paperless. He's been an accountant, a software developer, a manager in a very large corporation, and has run DocumentSnap since 2008. You can find Brooks on Twitter at @documentsnap or @brooksduncan. Thanks for stopping by.

Leave a Reply 130 comments

Breaks with PDFs on a NAS | Bruno - February 15, 2021 Reply

I have copied this script years ago, and even added a little confirmation dialog to delete the original PDFs after the merge. Worked like a charm. Until I decided to move my files to a Synology NAS. Now, when I run the automation on PDFs on the NAS the AppleScript complains that it can’t read the PDF ( I guess on the first one it tries).
Does anybody have an idea how the AppleScript can be changed so it works with files on a NAS?

Bob - June 18, 2020 Reply

Brilliant, thank you so much.
I didn’t know Automator was so fantastic!

Jeff Bush - September 10, 2019 Reply

Thanks Brooks, I used to have to use Acrobat every time I wanted to do this, your script is so much faster!

Peter Nelson - April 6, 2019 Reply

Very informative! Thanks for showing clearly how to combine PDF. I used to combine PDF with Acethinker PDF writer, free and works perfect. It is a cloud based software to merge PDF without install any software in your device. Share it here as an alternative method.

George K. - April 1, 2019 Reply

It’s 9 years later but this is still very useful. The beginning step has changed a little (the option is now “Quick Service,” which can be used as a system service) but everything else works like a charm. Automator is deceptive because you might think it is straightforward (I thought I could just create a service using “Combine PDF Pages”) but in fact it is anything but. THANKS.

Michael McCullough - March 17, 2019 Reply

Thank you! Has me thinking about how else I might use this tool.

This worked like a charm, except that the documents rotated. It’s easy enough to rotate in Reader, but I’d like to share this with folks in a way that they don’t have to take the step. Ideas?

Jorge - March 11, 2019 Reply

I was using this succesfully until Sierra. It is not longer working on High Sierra. Any idea how to fix it? Thanks!

Jamie Ross - October 23, 2018 Reply

This is killer awesome. Have been looking for a way to combine PDFs since I do this twice a month with multiple PDF files. Thanks so much for the tutorial and files.

Chris - July 12, 2018 Reply

Thank you. It works great.
Thanks for the zip file.

Brad - June 14, 2018 Reply

YOU ARE AWESOME.

Aaron - May 15, 2018 Reply

THANK YOU! However, I sometimes get this error with certain PDFs. Does anybody have any ideas? I think it may have something to do with the fact that if these PDFs are opened in Preview, I can’t Print to PDF. Perhaps there is a permissions error?

The action “Combine PDF Pages” encountered an error: “The operation couldn’t be completed. (com.apple.printing.automatoraction error -43.)”

Mary - April 7, 2018 Reply

Thank you very much !!! It’s amazing how many stuff we can do with automator !

mohammed - March 8, 2018 Reply

Thanks a lot. This was really helpful. especially the compressed file. you made it much easier for me. thanks again.

Susanne - January 28, 2018 Reply

Thanks so much for this great post!
One question – how do I put this into a loop, i.e. tell the automator function to go through one folder after the other? so that at the beginning of the whole procedure, instead of choosing the pdf files to combine, I choose the folders in which the automator should combine (all) the individual pdfs and save the result in the respective folder?

CortijoCopper - January 17, 2018 Reply

http://youtu.be/CuQArPdsRxg
Merge PDF Files on Mac

chimong - June 25, 2017 Reply

I tried to create a service following your instructions myself, but it didn’t work. I downloaded your zip file and it works fine. Didn’t know where I did wrong lol.

In the past I have been using “Combine PDF pages” from Library directly, but I was frustrated that it doesn’t append pages by name. For example, when I rename all my PDF pages I want to combine from 1 to 100, which is the order I intend, automator doesn’t combine from 1 to 100. Instead it combines in such an order as 1, 11, 12…2, 21…. It is the same if I rename my files 001, 002, …100. I don’t understand its logic and don’t know how to circumvent this seemingly simple problem. Am I missing some easy steps?

Thanks a lot!

edoardo - April 13, 2017 Reply

Hi, I was just looking for a easy way to combine pdf files on mac without additional software or using preview. Thank you very, VERY much for this tutorial, you just saved me many cumulative hours of work 🙂

Dallas Smuin - March 24, 2017 Reply

This has been working great. I have a question: If I have documents that have an odd number of pages and I want to make them all even before combining them. Is there a way for me to have the program identify the files that have odd number of pages and have them add a page at the end automatically, then proceed to combine the pdf? or will I need to do this manually?

Prasanna Karmarkar - March 16, 2017 Reply

Worked like a charm on El Capitan, and I ended learning a ton of new things. Brilliant post, thanks 🙂

Eddy - February 23, 2017 Reply

Wow! This is super useful and has just saved me a ton of time. I can’t wait to play around with automator more.

Iznaya Kennedy - February 12, 2017 Reply

So THAT’s what Automator is good for!!!

Tanya - December 28, 2016 Reply

Amazing! Just wanted to tell you how helpful this, along with your post on splitting PDFs was to me! Both worked like a charm on my MacBook Pro running Yosemite 10.10.5. Happy New Year and thank you so much for sharing this. -Tanya

Terramadre - December 27, 2016 Reply

Tried this and something didn’t quite work. I had used Automator in the past to combine pdfs and thought it had been easier. Still, I like the idea of a “Pre-set” option. Turned out the next site I found helped me create just that and it was much simpler. Here is the link to those instructions. https://paulminors.com/merge-pdfs-mac-automator/
Some steps are similar and I was glad I had already gone through these steps as they made it easier to locate certain actions required. Anyway, thanks for your tutorial.

Dale - November 5, 2016 Reply

This is one of the most helpful scripts I am using!

I have a question. I have some pages that I’ve made comments on (Draw Free Form), and those free form comments are not coming across into the combined PDF.

Is there another setting that I need to make so that they are included?

Thanks.

best,
Dale

Tim Willardson - November 4, 2016 Reply

Thank you. This is a great benefit.

Ryan - July 26, 2016 Reply

I downloaded this to combine pdf cover page’s to separate pdf document’s. The first couple times it worked perfectly.

Now, it keeps putting the cover page at the end of the document rather than the beginning. I’m selecting the document’s in order using the command key, just in case that was the issue, but nothing seems to change the outcome.

Has anyone else experienced this issue, or does anyone have any insight that may help?

    B - September 19, 2016 Reply

    Prbably too late but hope it helps whoever else. It will order them alphabetically, so name the pdf’s by the number you want them ordered 🙂