Skip to content

Instantly share code, notes, and snippets.

@fbeeper
Last active March 11, 2018 12:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbeeper/2d01c93d509e0bbf8662 to your computer and use it in GitHub Desktop.
Save fbeeper/2d01c93d509e0bbf8662 to your computer and use it in GitHub Desktop.

Securely encrypted ZIPs right from contextual menu in Mac OS

Run the following simple oneliner to download and "install" the service:

curl -L https://dl.dropbox.com/s/wpxbnm8y6gb6l32/compressWithPassword.tar.gz | tar zx -C ~/Library/Services/

And while selecting files or folders in Finder you will find the new option

Services > Compress with password

Note: as of today will only work with one file or directory at a time.

💥

Implementation details

Check passwordWithExpect.sh to see the script that this service runs.

Nothice that I didn't use zip's --password parameter that would entail the dangers of command logging. Instead, I used expect to pass the password directly to the zip function. Given that Automator services do not support expect scripts, I had to wrap it on a bash script. For the curious minds, -f - defines that expect will be using standard input. Then the following "$@ allows to send the function parameters to expect that will be extracted with [lindex $argv <number>]. Other than that you know what << means, and everything between ! will be the input sent to expect. Awesome, right?

doit (){
expect -f - "$@" <<\!
set timeout -1
set prompt {$ }
set password [lindex $argv 0]
#spawn the command
spawn zip -re [lindex $argv 1] [lindex $argv 2]
# Look for passwod prompt (twice)
expect "*?assword:*"
send "$password\r"
expect "*?assword:*"
send "$password\r"
expect $prompt
!
}
cd $(dirname "$2")
doit "$1" EncryptedArchive.zip "$(basename "$2")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment