Created
April 29, 2014 09:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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
See related: https://gist.github.com/faun/11390337