csmltd
August 23, 2016, 8:59am
1
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
Paul
1 Like
Hi
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. https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
See a video of it here: http://d.pr/v/15NFS
Keyboard Maestro “Merge pdfs in folder to new pdf” Macro
Merge pdfs in folder to new pdf.kmmacros (3.4 KB)
1 Like
csmltd
August 23, 2016, 10:37am
3
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
Regards
Paul
Hey Paul,
Automator has has a built-in Combine PDF Pages action.
http://macosxautomation.com/automator/combinePDFs/
Here's how to drive the Automator Action from AppleScript:
You can also use AppleScriptObjC:
Hi all, I need to merge many PDF into a single PDF file. I have 5 PDFs with different contents. All i need to do is Merge these files into a single PDF file thru apple script. Any help? -Rekha
Reading time: 9 mins đź•‘
Likes: 2 ❤
-Chris
2 Likes
csmltd
August 24, 2016, 6:05am
5
Hi Chris
Some awesome shares there - very much appreciated - THANK YOU !!
Kind Regards
Paul
1 Like
Motive8
February 10, 2018, 3:00am
6
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.
Suggestions?
Marc
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
Motive8
February 16, 2018, 10:40pm
9
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)
Motive8
February 20, 2018, 11:41pm
11
Thanks Jimmy,
Yes I am realizing there are many ways to write macros. I appreciate your input!
Marc
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)
2 Likes
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:
--ignore-case
Also – note that sort
may NOT handle UTF8 properly.
-Chris
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.
-Chris
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.
-Chris
I am using High Sierra 10.13.4