{"id":729,"date":"2020-05-25T15:36:10","date_gmt":"2020-05-25T22:36:10","guid":{"rendered":"https:\/\/52techtips.com\/blog\/?p=729"},"modified":"2020-05-25T15:41:53","modified_gmt":"2020-05-25T22:41:53","slug":"encrypt-and-password-protect-a-zip-on-a-mac-using-automator-service","status":"publish","type":"post","link":"https:\/\/52techtips.com\/blog\/2020\/05\/25\/encrypt-and-password-protect-a-zip-on-a-mac-using-automator-service\/","title":{"rendered":"Encrypt and Password Protect a .zip on a Mac using Automator Service"},"content":{"rendered":"\n<p>I recently needed to provide some sensitive documents to someone and the quickest method was email. However, I wanted to secure the contents (even just a little) before sending.<\/p>\n\n\n\n<p>I was able to quickly complete the task using the Terminal and entering the following command string thanks to an article I found on <a href=\"https:\/\/www.imore.com\/how-create-and-password-protect-zip-file-macos\" target=\"_blank\" rel=\"noreferrer noopener\">imore.com<\/a>. First change your directory in the terminal as this will eliminate the user path file structure being included in the saved zip.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zip -er FILENAME.zip FILESorFOLDERStoCOMPRESS<\/code><\/pre>\n\n\n\n<p>Later, I thought this might be something I&#8217;d need to do again and I wondered if there might be a way to turn this into a service or app. There are are several options out there, but <a rel=\"noreferrer noopener\" href=\"http:\/\/hints.macworld.com\/article.php?story=2013101622201160\" target=\"_blank\">this method<\/a> from Macworld has seemed to work great. I included the instructions below&#8230;<br><\/p>\n\n\n\n<p>OpenAutomator and choose &#8220;Service&#8221; (the gear). Change &#8220;Service receives selected&#8221; to Files or folders in &#8220;Finder.app&#8221;<\/p>\n\n\n\n<p>Add the &#8220;Run Applescript&#8221; step and then copy the code below and replace all the code in the &#8220;Run Applescript&#8221; command with this code.&nbsp;<\/p>\n\n\n\n<p>Choose save, naming it something like &#8220;Make Protected Zip&#8221;, then test it by going to the finder and selecting one or more files\/folders. Scroll down to the &#8220;Services&#8221; Menu and select the service with the name you just saved as.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>on run {input, parameters}\n\tset dialogResults to display dialog \"Name for zipped file (no extension)\" default answer \"Archive\" buttons {\"OK\", \"Cancel\"} default button \"OK\"\n\tif button returned of dialogResults is \"OK\" then\n\t\t\n\t\tset passwd to \"x\"\n\t\tset passwd_2 to \"y\"\n\t\trepeat while passwd \u2260 passwd_2\n\t\t\ttell application \"System Events\"\n\t\t\t\tactivate\n\t\t\t\tset passwd to text returned of (display dialog \"password for zipped file\" default answer \"\" buttons {\"OK\", \"Cancel\"} default button \"OK\" with hidden answer)\n\t\t\t\tset passwd_2 to text returned of (display dialog \"Please reenter your password\" default answer \"\" buttons {\"OK\", \"Cancel\"} default button \"OK\" with hidden answer)\n\t\t\tend tell\n\t\t\t\n\t\tend repeat\n\t\t\n\t\tset archiveName to text returned of dialogResults\n\t\t\n\t\ttell application \"Finder\"\n\t\t\tset archiveFileName to archiveName &amp; \".zip\"\n\t\t\t-- Append on a number if file exists.\n\t\t\tset suffix to 1\n\t\t\tset theFileExists to true\n\t\t\trepeat while theFileExists\n\t\t\t\ttry\n\t\t\t\t\tset archiveFile to ((container of (item 1 of input) as Unicode text) &amp; archiveFileName)\n\t\t\t\t\tif exists file archiveFile then\n\t\t\t\t\t\tset archiveFileName to archiveName &amp; suffix &amp; \".zip\"\n\t\t\t\t\t\tset suffix to suffix + 1\n\t\t\t\t\telse\n\t\t\t\t\t\tset theFileExists to false\n\t\t\t\t\tend if\n\t\t\t\tend try\n\t\t\tend repeat\n\t\tend tell\n\t\tset itemStr to \"\"\n\t\trepeat with thisItem in input\n\t\t\tset itemPath to quoted form of (POSIX path of thisItem)\n\t\t\ttell application \"Finder\"\n\t\t\t\tset parentFolder to POSIX path of (container of thisItem as alias)\n\t\t\tend tell\n\t\t\tset itemStr to itemStr &amp; \" \" &amp; itemPath\n\t\tend repeat\n\t\tset zipFile to quoted form of (parentFolder &amp; archiveFileName)\n\t\tset cmd to \"zip -P \" &amp; passwd &amp; \" -rj \" &amp; zipFile &amp; \" \" &amp; itemStr &amp; \" -x *.DS_Store\"\n\t\tdo shell script cmd\n\tend if\n\treturn\nend run<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to provide some sensitive documents to someone and the quickest method was email. However, I wanted to secure the contents (even just a little) before sending. I was able&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[223,222,189,229],"class_list":["post-729","post","type-post","status-publish","format-standard","hentry","category-technology","tag-mac","tag-technology","tag-terminal","tag-zip"],"_links":{"self":[{"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/posts\/729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/comments?post=729"}],"version-history":[{"count":2,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/posts\/729\/revisions"}],"predecessor-version":[{"id":731,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/posts\/729\/revisions\/731"}],"wp:attachment":[{"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/media?parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/categories?post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/52techtips.com\/blog\/wp-json\/wp\/v2\/tags?post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}