Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I create two Automator services that allow me to encrypt or decrypt files? So I would right click a file and click 'Encrypt', the .txt file would be encrypted to a .enc using openssl:

pass=$(osascript -e 'tell app (path to frontmost application as text)
text returned of (display dialog "Enter password:" default answer "")
for f in "$@"; do
    printf %s "$pass" | openssl enc -aes-256-cbc -salt -in "$f" -out "${f%.*}.enc" -pass stdin

Can I create a decrypt version that will give me the original .txt file back? Or can I write one service that knows if I want to encrypt or decrypt and run in the way necessary?

share|improve this question
up vote 0 down vote accepted

Select the service template, change the input type to files, add a Run Shell Script action, select pass input as arguments, and paste this script:

pass() {
    osascript - "$1" <<END
    on run args
    tell app (path to frontmost application as text)
    text returned of (display dialog ("Enter password for " & item 1 of args) default answer "")
    [ $? != 0 ] && exit 0

for f in "$@"; do
    if [[ "$f" == *.enc ]]; then
        pass "$f" | openssl enc -d -aes-256-cbc -pass stdin -in "$f" -out "${f%.enc}"
        pass "$f.enc" | openssl enc -aes-256-cbc -salt -pass stdin -in "$f" -out "$f.enc"
exit 0

It doesn't show specific error messages, you have to run the service again if you enter a wrong password, and there is no way to use the same password for multiple files. It would be easier to just do it from a shell.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.