PrintToVeraeTimeStamp/platform/macos/ipp/verae-print-command.sh
George Lambert b40e862082 feat(macos): Verae Timestamping in Print Destination list
Replace buried PDF Services as the primary UX with an IPP Everywhere
virtual printer (ippeveprinter LaunchAgent) named Verae Timestamping.
Jobs save {name}.pdf + {name}-verae-timestamp-{RECEIPTID}.pdf.
Also add /Applications/Verae Print Stamp.app for drop/Open With.
2026-10-03 04:10:17 -04:00

55 lines
1.5 KiB
Shell
Executable file

#!/bin/bash
# ippeveprinter -c handler: PDF (or PS) on stdin → Verae stamp with approved naming.
set -euo pipefail
LOG="${HOME}/Library/Logs/verae-print-ipp.log"
mkdir -p "$(dirname "$LOG")"
exec >>"$LOG" 2>&1
echo "$(date -u +%Y-%m-%dT%H:%MZ) IPP job start env=$(env | grep -E '^IPP_|^CONTENT_|^USER=' | tr '\n' ' ')"
VERAE_PRINT="${VERAE_PRINT_BIN:-$HOME/bin/verae-print}"
CHANNEL="${VERAE_PRINT_CHANNEL:-verae}"
OUT_DIR="${HOME}/Documents/Verae Timestamps"
mkdir -p "$OUT_DIR"
TITLE="${IPP_JOB_NAME:-${IPP_DOCUMENT_NAME:-document}}"
# Strip path / extension for stem
BASE="$(basename "$TITLE")"
STEM="${BASE%.*}"
STEM="$(echo "$STEM" | tr -cd 'A-Za-z0-9._ -' | head -c 80)"
STEM="${STEM:-document}"
TMPDIR="${TMPDIR:-/tmp}"
WORK="$(mktemp -d "${TMPDIR}/verae-ipp.XXXXXX")"
RAW="$WORK/job.bin"
PDF="$WORK/${STEM}.pdf"
# ippeveprinter may pass a spool file as argv[1], or feed bytes on stdin
if [[ $# -ge 1 && -f "${1:-}" ]]; then
echo "input file arg: $1"
cp "$1" "$RAW"
elif [[ ! -t 0 ]]; then
cat >"$RAW"
else
echo "ERROR: no document on stdin or argv" >&2
exit 1
fi
if [[ ! -s "$RAW" ]]; then
echo "ERROR: empty document" >&2
exit 1
fi
if [[ "$(head -c 4 "$RAW")" == "%PDF" ]]; then
cp "$RAW" "$PDF"
elif command -v /usr/bin/pstopdf >/dev/null 2>&1; then
/usr/bin/pstopdf "$RAW" -o "$PDF" || cp "$RAW" "$PDF"
else
cp "$RAW" "$PDF"
fi
echo "stamping stem=$STEM channel=$CHANNEL pdf=$PDF"
"$VERAE_PRINT" stamp -channel "$CHANNEL" -out-dir "$OUT_DIR" -name "$STEM" -open "$PDF"
echo "ATTR: job-impressions-completed=1" >&2
rm -rf "$WORK"
exit 0