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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
See related: https://gist.github.com/faun/11390337