Macro that adds a specific PDF to a batch of other PDFs

Hello!

I'm a teacher who receives certain student assignments as PDF files. Part of my grading workflow includes adding an assignment-specific grading sheet PDF to each student submission.

With the student submission files collected in a dedicated folder, I'd like to be able to tell a given assignment's grading sheet to copy itself to each file within that folder, and specify whether I want the grading sheet to become the first or last page.

I can do this in a sort of clunky way with Acrobat Pro, but I'm hoping to be able to use a macro to simplify. Ideally, the macro would prompt me for (a) the grading sheet file to be copied/added, (b) the folder directory containing the target files (student assignments), and (c) whether I want the grading sheet to become the first or last page (the number of pages in the student submission shouldn't matter).

I'm so open to suggestions! And I'm not picky about whether such a macro would use Acrobat, Preview, or just work within Finder or some other macOS magic. Thanks for any ideas!

Before I proceed any further with my solution, are you willing/able to install a free third-party command-line PDF utility? If you are, there's a pretty simple way to get this done.

-rob.

I went ahead and wrote it, as I thought it'd be an interesting learning exercise. This macro uses an open-source third-party PDF tool set called Coherent PDF, which makes the macro very simple, as it includes the ability to easily combine PDFs. The app itself is a command line (no GUI) app called cpdf.

Note that cpdf is from a non-Apple registered developer, which means you need to jump through some hoops to make is usable after installation; I've detailed the basic steps in a comment in the macro, but will provide some screenshots below, too.

Here's the macro:

Download Macro(s): PDF combiner.kmmacros (21 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • Tested on macOS 14 and macOS 15
  • Keyboard Maestro v11.0.3

The macro assumes you have installed the cpdf app in the /Applications folder; it will fail if you haven't done this. It also assumes you've already taken the steps to enable the app. Here's the full process, as required by Apple:

  1. Download the set of pre-built command line tools from the Coherent PDF site; here's the link: https://github.com/coherentgraphics/cpdf-binaries/archive/master.zip
  2. Open the expanded archive, and navigate into either the OSX-ARM or OSX-Intel folder, depending on which type of Mac you have.
  3. Drag and drop the cpdf app from that folder into your Applications folder.
  4. Switch to the Applications folder, and double-click the cpdf app. You will see this scary dialog:
  5. Click Done, then open System Settings > Privacy & Security.
  6. Scroll down to the Security section, where you should see this:
  7. Click Open Anyway. Apple, in their infinite wisdom, has decided that this still isn't proof enough you want to use the app, so...
  8. In this additional dialog, click Open Anyway:

At this point, Terminal will launch and you'll see some text you can ignore; you can then quit Terminal, and cpdf is ready to use.

The good news is you only have to do the above once on each Mac where you want to use cpdf. Once enabled, the macro should just work, as long as you put cpdf in the Applications folder.

Launch the macro, and it will prompt you for the grading sheet file and the folder of PDFS (it will ignore any non-PDFs in that folder). It will then ask whether the inserted page should be first or last, and then process all the files.

When done, the combined files will be in the same folder, with an "_" at the start of their names.

-rob.

1 Like