I have two scripts that I use for manipulating PDFs, and I'd like to merge them into a single one. However, I struggle to get the output from the first command to act as input for the second. Script one simply flattens the PDF with Ghostscript and modifies the file extension to differentiate the output from the original: Code: /usr/local/bin/gs -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$@.flat.pdf" "$@" Script two then locks the flattened PDF so that it can only be edited by those with the password: Code: /usr/local/bin/pdftk "$@" output "$@.locked.pdf" owner_pw foo I'd like this to be a single script. Can someone assist? Also, the use of the plain text password in the second script is unfortunate, but I don't yet know how to pull the password from Keychain Access. I know the CLI tools are there, but haven't successfully implemented them yet . If someone offered a clear example of implementing this that'd be great.