Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator/Applescript to encrypt & decrypt files

It took me some good internet searching to figure out how to do this, but I created Finder context menu options to encrypt and decrypt a file stored locally on my Mac. However, this only works if there's not a space in one of the folder names that the file is stored in. I'm hoping someone can help me fix that.


To create the context menu item, I started a new Automator "service" project, set it to "files or folders", and dragged in the "run applescript". My applescript for encrypting a file is:


********************************************************************************

on run {input, parameters}


tell application "Finder"

set sel to selection

if sel is not {} then

set als to sel's item 1 as alias

set aPath to POSIX path of als

display dialog "Enter a password for encryption" default answer "password"

set password1 to (text returned of result)

set scRi to "openssl des3 -in " & aPath & ".old -out " & aPath & " -k " & quoted form of password1

set RenameToOld to "mv " & aPath & " " & aPath & ".old"

set DeleteOld to "srm " & aPath & ".old"

--display dialog scRi

tell application "Terminal"

activate

do shell script (RenameToOld)

do shell script (scRi)

do shell script (DeleteOld)

end tell


end if

end tell

return input

end run

********************************************************************************


I have a similar one set up for decrypting. I'm sure the error is resulting because the space forces OpenSSL to think there's a new argument being passed. The question is, what do I need to do in my script to account for this?


Thanks!

13" MB Pro Late 2009 model, Mac OS X (10.6.6)

Posted on Jul 22, 2012 3:05 PM

Reply
Question marked as Best reply

Posted on Jul 22, 2012 3:20 PM

Just quote the file paths, like you did with the password, for example


quoted formofaPath

2 replies

Jul 22, 2012 6:21 PM in response to red_menace

Thanks - for some reason I was having problems with quoted form earlier. Here's the finished script if anyone is interested:


on run {input, parameters}

tell application "Finder"

set sel to selection

if sel is not {} then

set als to sel's item 1 as alias

set aPath to POSIX path of als

set oldPath to aPath & ".old"

set oldPath2 to quoted form of oldPath

set aPath2 to quoted form of aPath

display dialog "Enter a password for encryption" default answer "password"

set password1 to (text returned of result)

set scRi to "openssl des3 -in " & oldPath2 & " -out " & aPath2 & " -k " & quoted form of password1

set RenameToOld to "mv " & aPath2 & " " & oldPath2

set DeleteOld to "srm " & oldPath2

--display dialog scRi

tell application "Terminal"

activate

do shell script (RenameToOld)

do shell script (scRi)

do shell script (DeleteOld)

end tell

end if

end tell

return input

end run

Automator/Applescript to encrypt & decrypt files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.