There’s quite a lot to unpack here:
Firstly, Automator has an Apply Quartz Filter action, which is a lot easier to user than AppleScript. (Quartz Filters are an OS feature, not just Preview’s.)
Secondly, the OS-bundled filter to Reduce file size is well-known for being terrible, and you can find various third-party filters that provide better settings. Or you can create your own filter in ColorSync Utility, as per my answer here.
Thirdly, Apple made a lot of changes to PDFKit in Sierra, and with that came many bugs in PDF creation and manipulation. Most of these were fixed in High Sierra, but some lingered until Mojave. Any Mac running Sierra should be capable of running High Sierra, at least.
If there’s a compelling reason why you need to stay on Sierra, then I’d suggest downloading a compatible version of GhostScript, which should be able to batch-compress PDFs very easily.
Also, it looks like you’re using a Guest user account? (Unless that’s your name.) It’s possible that a guest account has restricted permissions, which might cause problems.
As for the AppleScript itself, it looks like there’s no such command as export
in the Preview AS dictionary. (There isn’t in Sonoma, at least: but you should check the dictionary in Sierra.)
One final thing about your shell script: The ‘weird characters’ in the Terminal output were actually the data contents of the PDF file being written to stdout
. The -o
flag passes options to the print driver; it doesn’t set the output file. Also -p
sets the PPD to be used. You can’t apply a Quartz Filter to cupsfilter. (CUPS has its own ‘filters’, which are a completely different thing.)