pdf-tools/scripts/scrub-and-mail.sh
Eric Furst e464871b69 Initial public release of pdf-tools
Command-line tools for marked-up PDFs and scanned handwritten notes:
pdf-scrub, pdf-notes-md, scan-notes-md (Ollama by default, Claude on
request), scan-notes-index (per-page search metadata), and
scan-notes-stats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZSvbNaLhgFuTm7wmkgbWs
2026-11-03 07:25:51 -05:00

49 lines
1.4 KiB
Bash
Executable file

#!/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 <pdf>" >&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 <<APPLESCRIPT
set theAttachment to POSIX file "$OUT"
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"$BASENAME"}
tell theMessage
make new attachment with properties {file name:theAttachment} at after last paragraph
end tell
activate
end tell
APPLESCRIPT
echo "opened Mail with: $OUT" >&2