https://gist.github.com/Pezmc/38017cb03daccb17d3835280c568dc0f

#!/bin/bash
# This script takes a PDF or list of PDFs and outputs a file(s)
# named <file>_scanned.pdf that looks like it has been scanned
#
# Requires imagemagic and popper to be installed (brew install imagemagick poppler)
#
# Accepts: a list of files
# Usage: ./<scriptfilename> pdf1.pdf pdf2.pdf
#
# To use as a macOS automator quick action you need to:
# - Create a new quick action that receives files or folders
# - Add a shell script
# - Paste in this script
set -e
 
export PATH=/usr/local/bin:$PATH
for file in "$@"; do
  base=${file%.pdf}
  base=$base"_scanned.pdf"
 
  # Remove all temp pdfs before
  # rm -f /tmp/fake-scan-split-*.pdf
 
  # Split PDF into pages
  echo "Splitting $base into separate pages"
  /opt/homebrew/bin/pdfseparate "$file" /tmp/fake-scan-split-%04d.pdf
 
  # Loop over the pages
  for splitFile in /tmp/fake-scan-split-*.pdf; do
    splitFileBase=${splitFile%.pdf}
    splitFileScanned=$splitFileBase"_scanned.pdf"
 
    # Slightly rotate page, add a bit of noise and output a flat pdf
    /opt/homebrew/bin/convert -density 130 -trim -flatten "$splitFile" -attenuate 0.2 +noise Gaussian -rotate "$([ $((RANDOM % 2)) -eq 1 ] && echo -)0.$(($RANDOM % 8 + 1))" \( +clone -background black -shadow 30x5+5+5 \) +swap -background white -layers merge +repage "$splitFileScanned"
    echo "Output page $splitFileBase to $splitFileScanned"
  done
 
  # Combine the PDFs, add noise across the entire document, apply sharpening, convert to b&w, soften the blacks slightly
  /opt/homebrew/bin/convert -density 130 $(ls -rt /tmp/fake-scan-split-*_scanned.pdf) -attenuate 0.2 +noise Multiplicative -sharpen 0x1.0 -colorspace Gray +level 15%,100% "$base"
  # /opt/homebrew/bin/convert rose: ( +clone  -background navy  -shadow 80x3+5+5 ) -density 130 $(ls -rt /tmp/fake-scan-split-*_scanned.pdf) -attenuate 0.2 +noise Multiplicative -sharpen 0x1.0 -colorspace Gray +level 15%,100% "$base"
  echo "PDF re-combined to $base"
 
  # Remove all the temporary PDFs
  echo "Cleaning up"
  rm /tmp/fake-scan-split-*.pdf
done