Merging PDF Documents

Hi Chris

Some awesome shares there - very much appreciated - THANK YOU !!

Kind Regards

1 Like

Hey Jimmy, I just saw this and its great thank you. New to KM and want to use your macro. I want to change one thing though and perhaps you could offer a suggestion. I want to delete the files in the folder AFTER the files are merged into a new one, leaving just the merged pdf file.



Hi Marc

It is easy to just add a Trash action at the end, which trashes %Variable%Path%.

Here is a macro which does this.
It has also been updatede to support the new Split path-action in KM 8 and to use local variables.

Keyboard Maestro 8.0.5 “Merge pdfs in folder to new pdf” Macro

Merge pdfs in folder to new pdf.kmmacros (3.2 KB)

1 Like

Thanks Jimmy!

Hey Jimmy

Thanks again. I’m playing around with this trying to learn etc. I’m curious, could this work if the files were not put into a folder? For example, just clicking on two or more files in finder? Or, do the files need to be in a folder?

Yes, that is possible.

Somebody could probably have made it as a shorter macro.

But below is my take on it.

It start by asking for a filename and if files needs to be trashed.

Keyboard Maestro 8.1 “Merge selected pdfs to new pdf” Macro

Merge selected pdfs to new pdf.kmmacros (6.9 KB)

Thanks Jimmy,

Yes I am realizing there are many ways to write macros. I appreciate your input!


And now I have optimised the macro, so that it does not create the temporary folder.

This was done after reading @peternlewis method to pass multiple paths to the execute script action here: Run Single Command on Finder Selection

Keyboard Maestro 8.1.1 “Merge selected pdfs to new pdf-v2” Macro

Merge selected pdfs to new pdf-v2.kmmacros (7.3 KB)


Great! Thanks!

Probably the last update.

Now the variables in the Prompt for User Input is local variables.
Keyboard Maestro 8.1.1 “Merge selected pdfs to new pdf-v3” Macro

Merge selected pdfs to new pdf-v3.kmmacros (6.9 KB)

I have updated the macro again, because I noticed the files were not merged alphabetically.
This has now been solved.

Keyboard Maestro 8.2.1 “Merge selected pdfs to new pdf-v4” Macro

Merge selected pdfs to new pdf-v4.kmmacros (7.5 KB)

Hey Jimmy,

That's odd. The Finder-Selection action should return items sorted the same as shown in the Finder with name-sort.

Can you provide a sample of items that were NOT merged alphabetically?

The actual sort and the desired sort?

Also – note that the way you're using sort will separate uppercase from lowercase.

Unless you want this to be so, you need this switch:


Also – note that sort may NOT handle UTF8 properly.


Hey Jimmy,

I ran some tests, and Apple has changed how AppleScript acquires selected items. It now honors the Finder-sort -- it used to return items alpha-sorted no matter what the Finder-sort was.

So the sample I requested is now moot.


In my test I got last created first in the merged file. Then second last created and so on.
Maybe it honours how I selected the files?
I selected the last and hold down shift and selected the first.

That's possible.

Which version of macOS are you using? I'm on macOS 10.12.6.


I am using High Sierra 10.13.4

Thanks for this great macro!

However, I’m running into the following issue:

2018-11-15 10:41:19 pdftk /Users/dms/ZEVRIX/test/fiche-technique-DucoBox-Eco-p1.pdf /Users/dms/ZEVRIX/test/fiche-technique-DucoBox-Eco-p2.pdf /Users/dms/ZEVRIX/test/fiche-technique-DucoBox-Eco-p3.pdf cat output /Users/dms/ZEVRIX/test/test.pdf

xargs: pdftk: No such file or directory

Macro “Merge selected pdfs to new pdf-v4” cancelled (while executing Execute Shell Script).

The PDF toolkit has been installed. If I manually use pdftk using terminal, I don’t get any ‘no such file or directory’ error.

Any ideas?

Hey @dmduco,

It looks like you have a path problem. Take a look at this, and see if it helps you solve it.

Create a PATH Environment Variable for Keyboard Maestro and Add /usr/local/bin to the Default Path


Hey @dmduco,

You can find where pdftk is located by running this in the Terminal:

type pdftk

You'll get a result that looks something like this:

pdftk is /usr/local/bin/pdftk

If you run the Terminal command in an Execute a Shell Script action you can find out if Keyboard Maestro see it.

A bit more info:

Some information on the Unix PATH


@ccstone, you're awesome!

I went with the variable method to get the unix path correct, so I don't have to mess around in the original action.
Macro is running great now! (it works much faster than a similar action for automator btw)