Merge PDFs Natively With A Right-Click In OS X

UPDATE: If you installed this script today (2016-08-15), you may need to update it.  I added a line in the script that should prevent duplicate pages from being appended.

There are plenty of apps that help you merge PDFs into a single file, but if you want something faster with a “native” feel, you can set up an OS X service to quickly merge selected PDFs simply by right-clicking them.

right-click-merge-pdf

Setting It Up

First, open Terminal an enter this command to install the Python module that makes this possible:

sudo easy_install PyPDF2

Open Automator and choose Service

select service

Select files or folders in Finder.app using the pulldown menus near the top of the window that opens.

service receives

Search for get finder, then drag Get Selected Finder Items from the left pane into the right.

get finder items

Next, search for script, drag Run Shell Script over.  Using the pulldown menus, choose /usr/bin/python for the Shell: and as arguments for Pass input:

python arguments

Paste in the script below.

Your final product should look like this:

 

complete product

Finally, save the workflow as Merge PDFs and it will become available in your right-click menu when using the Finder.save as merge pdfs

I have found this to be especially useful for when I need to submit a form with an attached document such as when submitting medical reimbursements or other medical requests.

29 Replies to “Merge PDFs Natively With A Right-Click In OS X”

  1. Wonderful except that using this method, my merged PDF duplicates. Output should be a 15 page document but it is 30. I don’t see the error in the workflow. Very useful if I can find how this can be corrected.

    1. Hmm someone else ran into this, too. The logic looks OK in the for loop. I wonder if PyPDF2 does something else with multi-page documents. I guess I should have accounted for that, but I am always merging a bunch of single page documents. Nonetheless, I’ll try to take a look and figure out why it does that.

      1. Correct. Among other uses I have three PDFs to merge daily. The first is one page, second is random five to fifteen pages and the third PDF is one page.

        1. Yeah, I just tried with a hundred plus page document and it turned out like three times as many pages. I’ll need to debug it more…

          1. The issue is that when the workflow is saved as a service, the “Get Selected items from Finder” action is already implied, even if you don’t have that action in your workflow. So the “Get Selected Items from Finder” action in this workflow is redundant. Removing it solved the issue for me, but only when the workflow is saved as a service

    2. OK, I think it might have to do with the file not getting closed throughout the loop…just need to figure out how to close it.

    1. You are probably trying to merge a non-standard PDF or the PDF has something weird about it. Try some different PDFs to see if you get the same result.

  2. Very good idea, wish I’d thought to automate this earlier.

    But there’s a much easier way:

    Skip the first step installing the python module.

    Instead of adding a “Run Shell Script” piece to your automator workflow, go to the PDFs section and insert a “Combine PDF Pages” piece. The default “append” setting is probably what you want.

    Don’t know if this part is necessary, but it’s what I did and it worked great: go to the “Files and Folders” section of actions, and insert a “Open Finder items” action right after your “Combine PDF Pages”.

    For me, this workflow works perfectly to open the merged document with all pages in Preview, where I can then save them (or reorder the pages manually if I want, etc.).

    1. Yeah, that’s definitely an option and I used it for a while. I found that to be much slower, however. In addition, I plan on doing some more with the file naming and placement so using Python makes it much more expandable and easier to customize.

  3. Love this, but can’t get it to work for files on my Desktop 🙁 Am running OS X Sierra Beta if that’s significant, so my Desktop is backed up w/ iCloud

    1. Hmm, I haven’t tried it in the beta yet…you could try to run it directly from Terminal by saving the script to a file and passing the files as arguments. If it works that way, then the problem is with Automator or the Service service.

  4. Unfortunately mine still duplicates everything that’s merged. I’ve triple checked I’m using the latest code, and it’s still happening. It doesn’t matter what PDFs I try and merge.

    1. The issue is that when the workflow is saved as a service, the “Get Selected items from Finder” action is already implied, even if you don’t have that action in your workflow. So the “Get Selected Items from Finder” action in this workflow is redundant. Removing it solved the issue for me, but only when the workflow is saved as a service.

  5. Unfortunately mine still duplicates everything that’s merged. I’ve triple checked I’m using the latest code, and it’s still happening. It doesn’t matter what PDFs I try and merge.

  6. The issue is that when the workflow is saved as a service, the “Get Selected items from Finder” action is already implied, even if you don’t have that action in your workflow. So the “Get Selected Items from Finder” action in this workflow is redundant. Removing it solved the issue for me, but only when the workflow is saved as a service.

Leave a Reply