Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Owner

faun commented Apr 29, 2014

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