Merging PDF Documents

Hi All

I am new here and have turned to KM in the hope of being able to automatically merge pdf documents and then rename and save the resultant file in my folder system.

Would anybody have a macro for this workflow or could advise on it ??

Kind Regards

1 Like


I have made a macro, which merges the selected folder to a pdf with the same name as the folder.
So all pdfs in the folder is combined into a pdf.

It relies on the command-line utility named PDFTK. You can find it here.

See a video of it here:

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

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

1 Like

Hi Jimmy

I greatly appreciate your speedy and detailed response - I will now set about reviewing the macro in order that I may learn further about its process.

Many many thx


Hey Paul,

Automator has has a built-in Combine PDF Pages action.

Here's how to drive the Automator Action from AppleScript:

You can also use AppleScriptObjC:



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)

1 Like

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