Hazel - Join PDF Files

I have found a qpdf script to combined pdf files. However, I get an error. Any idea how to make this script work?

for f in $1; do qpdf --empty "${f%.pdf}-joined.pdf" --pages "${f%.pdf}"*.pdf --; done

The error does not tell me much: “less than a minute ago : Error processing shell script on file 1.pdf.”

However, running this command in Terminal works.

qpdf --empty --pages *.pdf '--' output.pdf

Source

I don’t know how to script so I gave up on that idea. Instead, I came up with a Siri Shortcut to achieve what I want.

The only problem is that I manually have to run it once per week. Passing folder as input from Hazel does not seem to work.

Link: Shortcuts

You already started scripting when you started using the command line and tools like Shortcuts.

Mr_Noodle is telling you that when you run a command from Hazel, it doesn’t know where to find it. This is because there’s stuff that gets set up when you open the command line. Your environment, Part of the configuration of that environment indicates places to look for commands if the full path to the command isn’t specified.

The full path for a command is the path that identifies where on your drive the command has been installed.

You can use the which command to find where installations might be. For example, if I type whicch qpdf at the command line on my Mac, I can see QPDF is installed in the usr/local/bin/' directory, and so the full path to qpdf would be /usr/local/bin/qpdf.

2023-01-11-22.20.02@2x

So I might modify your original script to this to specify the full path:

for f in $1; do /usr/local/bin/qpdf --empty "${f%.pdf}-joined.pdf" --pages "${f%.pdf}"*.pdf --; done

I came up with a Siri Shortcut to achieve what I want.

:+1:t2:

The only problem is that I manually have to run it once per week. Passing folder as input from Hazel does not seem to work.

It isn’t clear what your Hazel trigger is to pass a folder (rather than process each file). I would also expect that Hazel would be passing Shortcuts a folder path as text, so your shortcut would need to deal with a folder path as input rather than folder text.

Apologies for the old version, I have the newer Hazel on my daily driver Mac, but an old one on an old OS on my Mac mini I run as a headless server. This is the one I can push jobs out to (via Dropbox), and that happens to include combining PDFs.

What I do is I load up all my PDFs to merge in a designated folder (files named to order them in the order I want them merged) that is not watched by Hazel. I have another folder which is watched by Hazel, which looks for the merge.txt file being added. When it finds it, it trashes the file after running an Automator workflow.

Once again, this is an old set up, and so is using Automator. Now you could certainly use a Shortcut in its place, and that is very much what I would recommend. However, I’ll include a screenshot of the Automator workflow just for reference.

The key point here for you is that Hazel passes no information to Automator. Automator will only look in one place, and Hazel is just the trigger mechanism for the workflow.

In terms of creating the merge file, I have had various ways of creating the file in Dropbox. Where Dropbox has been sync’d locally on Mac or Windows, simple scripts did the job for me and I’d just run via a keyboard shortcut. I could also write the file to Dropbox using Shortcuts on my i*OS devices, trigger it via an IFTTT applet, etc. So I never manually created the trigger file. I think I can even do it inside my network via a remote Keyboard Maestro call to trigger a macro on the Mac mini to write the file.

Hopefully, that gives you some clarity around the points you’ve been having trouble with.