ALYB
December 10, 2021, 9:32am
1
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)
ccstone
December 10, 2021, 10:57am
2
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)
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
ALYB
December 20, 2021, 8:02am
3
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
ccstone
December 20, 2021, 6:42pm
4
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)
1 Like
ALYB
December 21, 2021, 7:40am
5
Hey Chris,
I must be doing something wrong here:
Gives:
Puzzled ...
ccstone
December 21, 2021, 7:45am
6
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
ALYB
December 21, 2021, 7:49am
7
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
ccstone
December 21, 2021, 7:54am
8
You ran this from the Terminal.app – not a Keyboard Maestro Execute a Shell Script action – yes?
ALYB
December 21, 2021, 8:06am
9
Correct. From such an action I get:
ccstone
December 21, 2021, 8:27pm
10
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
ALYB
December 22, 2021, 7:07am
11
Thanks again!
BTW: I really have no idea how to read this. Colons and slashes in one path? How to interpret this?
ccstone
December 22, 2021, 4:38pm
12
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