Merging PDF Documents

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

-Chris

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

-Chris

@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)

2 Likes

Any idea how I can control the order of the files? If possible, I would like them to be in order of date modified. I tried adding a For Each Path in folder but couldn't get it to work.

Thanks

Do you actually have pdftk installed?

I do not know how to do that. This macro just sorts it alphabetically.

1 Like

Yes, I do. And the Macro works; I would just prefer to be able to merge the documents in a different order.

How are you getting the files "into" your macro? Both AppleScript's and KM's "selected items" honour the Finder's current sort mode, so you could select your files and sort by "Date Modified" before triggering the macro.

Nice idea. The problem is that the macro -- or maybe pdtkf when called with wildcards -- sorts into alphabetical order and then combines the files. At least, I think that is what is going on.

I did have an Automator workflow that did what I needed, but it seems to be broken with changes to the combine PDFs command.

Possibly I could use A Better Finder Renamer to rename the files adding a prefix in order of modification date. That's one I need to investigate to see how it might work with KM.

Ah -- @JimmyHartington's put in an explicit "Sort" action to make it ASCII order regardless of Finder sort settings:

image

Disable that and you'll probably (untested) get the files merged in Finder order.

(Yes, shell globbing does result in an ASCII-sorted list, but I can't see that going on here.)

1 Like

I tried, but got an error I am not yet capable of figuring out. I have reverted to my original plan of renaming with ABFR and then using the original version 1 of this macro.

Two steps, for now, but still better than what I was doing before, so I will take it.

Thanks for all your help. KM is clearly very powerful, and will need more study.

Not a small instruction :grinning:

  1. Open Automator and select "New Document".
  2. Choose "Folder Action" and click "Choose".
  3. In the top right corner, choose the folder where you want to add the PDF documents.
  4. From the Actions panel on the left, find and add the "Combine PDF Pages" action to the workflow.
  5. Choose your settings for merging the PDF documents, such as whether to combine all pages or just specific pages.
  6. Add the "Rename Finder Items" action to the workflow.
  7. Choose your settings for renaming the merged PDF file, such as using a custom name or adding a suffix.
  8. Add the "Move Finder Items" action to the workflow.
  9. Choose the folder where you want to save the merged and renamed PDF file.