This one is a bit more complicated.
It will take the selected files or folders and combine the pdfs into a single file.
For files, it will save the combined pdf in the same folder as the first file selected, and use the name you choose.
For folders, it will save the combined file inside the folder using the folder name as the file name.
If you select both files and folders, it will combine the individual files into one file, and the files in the folder into another file.
- Open Automator and create a New Service -- cmd-N, then select Service as the type.
You should see a Library pane on the left and a blank workflow pane on the right.
- At the top of the workflow pane, set it to:
Service receives selected files or folders in Finder
- From the Library pane, select Utilities
- From the Actions list, drag in a Set value of variable Action
Set the name of the variable to "AllItems"
- From the Files & Folders Library, drag in a Filter Finder Items Action
Set it to:
- All of the following are true
- From the Actions list, drag the Run Shell Script Action into the workflow pane
- Leave the Shell: /bin/bash
- Set Pass input: as arguments
- Replace the code for the shell script with:
for f in "$@"
do
find "$f" -name ".DS_Store" -exec rm -f {} \;
dot_clean -m "$f"
fileName="$f"/$(basename "$f").pdf
/usr/local/bin/cpdf -merge -idir "$f" -o "$fileName"
done
- From Utilities, drag in a Get Value of Variable
- Select AllItems from the List
- Right-click on the Action, near the top, middle and select Ignore Input

on run {input, parameters}
if input is not {} then
set MyFileName to text returned of (display dialog "Enter a file name for merged PDFs:" default answer "Combined PDFs" buttons {"Cancel", "Merge"} default button "Merge")
set pathList to {}
repeat with anItem in items of input
set pathList to pathList & POSIX path of anItem
end repeat
return (MyFileName as list) & pathList
end if
end run
Drag in another Run Shell Script Action
- Leave the Shell: /bin/bash
- Set Pass input: as arguments
- Set the code to:
fileName="$1"
if [ $# -lt 2 ]; then
exit 0
else
filePath=$(dirname "$2")/"$fileName".pdf
/usr/local/bin/cpdf -merge "${@:2}" -o "$filePath"
fi
Save this Service as something like Merge PDFs.
Select Files, Folders, or Files and Folders
Right-click on the selection and choose Merge PDFs from the Services submenu.
It will overwrite the file without warning if you run it again on a folder. So, if you want to preserve a generated file, rename or move it before running the Service on that folder again.
I didn't combine the other two processes, but I think I could do it by asking you if you want to OCR, or OCR and K2.
If you just run it through k2pdfopt, does it have the same options as when you OCR first?
Also, are the files always PDFs? Or can they be image, text, or other types. I didn't dig deep into the manual for cpdf, but it seemed like it only handled PDFs.