Shell script to combine PDFs, renaming output I am trying to automate some accounting tasks. For this purpose I have employed Noodlesoft Hazel's help to rename and sort documents. However, I am stuck at trying to combine PDFs that really belong together (i.e. invoice from vendor with receipt from payment portal for the same purchase).

More specifically, the names of the documents to be combined have the same first part, say:

2017-02-01 Vendor1 - invoice1234.pdf
2017-02-01 Vendor1 [PayPal] - transactionID.pdf


Is there a way to combine them automatically (i.e. running a shell script in Hazel), possibly using pdfunite? It would be important to retain the name of the second file, but combine the two into one PDF.

I have some basic scripting knowledge and would be up for the challenge!
A linked question How can I combine PDF files and automatically create a table of contents? offers a program to do this. I don't know the syntax for scripting it with hazel/applescript/automator/ruby what have you though.