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)