#!/usr/bin/env bash # scrub-and-mail.sh — scrub a PDF and open a new Mail.app message with it attached. # # Usage: # scrub-and-mail.sh /path/to/file.pdf # # Designed to be called from a macOS Quick Action / Service / Shortcut # with the selected PDF passed as $1. set -euo pipefail if [[ $# -lt 1 ]]; then echo "usage: $0 " >&2 exit 64 fi IN="$1" if [[ ! -f "$IN" ]]; then echo "error: not a file: $IN" >&2 exit 1 fi # Write the scrubbed copy to a temp dir so we don't pollute Dropbox. TMPDIR_OUT="$(mktemp -d -t pdfscrub)" BASENAME="$(basename "$IN" .pdf)" OUT="$TMPDIR_OUT/${BASENAME}_clean.pdf" # Resolve the CLI. Prefer the installed entry point; fall back to # `uv run` from the project directory if you keep it ephemeral. if command -v pdf-scrub >/dev/null 2>&1; then pdf-scrub "$IN" -o "$OUT" >/dev/null else : "${PDF_TOOLS_DIR:?set PDF_TOOLS_DIR to the project path or install pdf-scrub}" (cd "$PDF_TOOLS_DIR" && uv run pdf-scrub "$IN" -o "$OUT" >/dev/null) fi # Hand off to Mail.app. POSIX path -> HFS path for AppleScript's `file`. osascript <&2