Skip to content

Instantly share code, notes, and snippets.

@faun
Created April 29, 2014 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faun/11394915 to your computer and use it in GitHub Desktop.
Save faun/11394915 to your computer and use it in GitHub Desktop.
Service to decrypt all selected PDFs. This script is intended for use in an automator workflow. Files and folders selected should be passed in as arguments.
#! /bin/sh
password=$(security 2> /dev/null find-generic-password -a login -s decrypt_pdfs -D "application password" -w)
set -e
decrypt_file () {
source_file="$1"
filename="$(basename "$source_file")"
directory="$(dirname "$source_file")/decrypted"
destination="$directory/$filename"
mkdir -p "$directory"
qpdf --decrypt --password="$password" "$source_file" "$destination"
}
for arg in "$@"; do
if [[ -d $arg ]]; then
for file in "$arg"/*.pdf; do
decrypt_file "$file"
done
elif [[ -f $arg ]]; then
decrypt_file "$arg"
fi
done
@faun
Copy link
Author

faun commented Apr 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment