Macro to Merge PDFs Stopped Working After Upgrade to Big Sur

I have this macro to merge PDFs in a folder on my Desktop to one PDF. It worked fine on Catalina, but after my upgrade to Big Sur it stopped working. I cannot find the cause. Please help ...

Output of the macro:

The macro itself:


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

Hey Hans,

Is pdftk installed?

Paste this into the Terminal and hit return:

type pdftk

Your macro doesn't work for me here on Mojave, and I'm not seeing how it could have worked in the first place.

It loops for every file in the Finder selection and runs the shell script each time – you need to compose the shell command with the quoted file paths and then run it:

pdftk '/Users/SomeUser/test_directory/TEMP/ONE.pdf' '/Users/SomeUser/test_directory/TEMP/THREE.pdf' '/Users/SomeUser/test_directory/TEMP/TWO.pdf' cat output OutPutName.pdf

Your loop should produce only the quoted file paths:

'/Users/SomeUser/test_directory/TEMP/ONE.pdf' '/Users/SomeUser/test_directory/TEMP/THREE.pdf' '/Users/SomeUser/test_directory/TEMP/TWO.pdf'

Your Execute a Shell Script action should be after the loop and should look something like this:

pdftk "$KMVAR_PathList" cat output "$KMVAR_ParentPath"/"$KMVAR_OutputFileName".pdf

To see how you're going wrong – replace the Execute a Shell Script action in your macro with this one:

Execute a Shell Script.kmactions (901 B)
Keyboard Maestro Export

I've used echo to output the text of the shell script INSTEAD of running it. Eyeball the output, and it unveils your troubles.

-Chris

1 Like

Hey Chris,

Sorry for the late respons.

The original macro was created by @JimmyHartington: Merging PDF Documents - #3 by csmltd

I get this output:

pdftk "/Users/hl/Desktop/REF"*.pdf cat output "/Users/hl/Desktop"/"REF".pdf

BTW: Since I'll always use this macro to create a PDF file /Users/hl/Dropbox/CT/Jobs/REF.pdf from all files in the folder /Users/hl/Desktop/REF, the Finder selection part can be omitted.

I found that with Big Sur there's now a dedicated Quick Action: How to Combine Files Into a PDF on Mac

Hey Hans,

In that case then you only need one Execute a Shell Script action.

-Chris


Merge PDF Files in a Folder to the Desktop v1.00.kmmacros (6.0 KB)
Keyboard Maestro Export

1 Like

Hey Chris,

I must be doing something wrong here:

Gives:

Puzzled ...

Hey Hans,

Do you have a Keyboard Maestro variable ENV_PATH that defines your system path?

What does type pdftk return when run in the Terminal.app?

What does echo $PATH return when run from an Execute a Shell Script action?

-Chris

Hey Chris,

I haven't defined ENV_PATH.

I get:

pdftk is /usr/local/bin/pdftk

And:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public

You ran this from the Terminal.app – not a Keyboard Maestro Execute a Shell Script action – yes?

Correct. From such an action I get:

Create a variable in the Keyboard Maestro Editor's preferences variables panel named ENV_PATH

Put this path in it:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:

Then you'll be able to call pdftk properly.

Keyboard Maestro does NOT synchronize paths with your Terminal environment by design. You the user have to set it up according to your needs.

-Chris

1 Like

Thanks again!

BTW: I really have no idea how to read this. Colons and slashes in one path? How to interpret this?

Colon characters are illegal in POSIX Path strings, so the colon was chosen as a separator character between discrete paths in the system $PATH.

If you replace the colon character with a newline you'll see what the $PATH means to the system with a search order from top to bottom.

-Chris

1 Like