This summer we had thousands of exam scripts submitted as pdf files which had to be marked by annotation. They arrived as folders containing pdf files named by alphanumeric candidate ‘number’, and marks had to be recorded in a spreadsheet sorted by candidate number.

I wanted to have a script that would open the alphabetically first file in a folder using the xournalpp software I use for annotation, wait for me to finish marking and close the file, then automatically open the next, and so on. The aim was to speed up the process, to avoid mistakes where some file gets accidentally skipped, and to ensure the files come in alphabetical order so that entering marks into the spreadsheet is faster and less error-prone.

I use a tiling window manager xmonad so that I could have the marks spreadsheet filling one half of the screen and xournalpp filling the rest without having to make any adjustments.

Only a single line of unix shell is needed:

find -maxdepth 1 . -type f -iname '*.pdf' -print0 | sort -z | xargs -0 -n1 xournalpp

The find command finds all files (-type f) ending with .pdf (case insensitive thansk to -iname) and outputs the full filename followed by a null (-print0). This is so we can split the output on nulls, not spaces, to avoid any issues with spaces in filenames. -maxdepth 1 makes it only find files in the current folder, not subfolders (I wanted to mark in batches with unmarked files in a subfolder).

sort -z sorts alphabetically using null termination to split items.

xargs -0 is null-terminated input items, n1 means pass one at a time to the xournalpp command.