2

I would like to use "Quick Actions" within the Finder app from a selection of files and/or folders to make a password protected ZIP file.

  • 3
    If this is the solution/answer, can you please rewrite the question to actually be a question and then post the solution as an answer below? It might help to provide some more context then, including how to combine this with Automator. – nohillside Sep 24 at 15:28
1

This is not a direct solution, however it can be used as an alternate solution because it will create a disk image (.dmg) file of all selected Finder files and or folders, whether the selection is a single item or multiple items.

global myPassword

property destinationFolder : (path to documents folder)
property theName : missing value
property isTrue : missing value

set theName to "New Encrypted Disk Image"

run setPassword
delay 0.1
activate
set deleteOriginals to button returned of (display dialog "Would You Like To Delete The Original Files After The Disk Image Has Been Created?" buttons {"Yes", "No"} default button 1)
delay 0.1
activate
set theName to (display dialog ¬
    "Would You Like To Name Your New Disk Image?" default answer ¬
    "New Encrypted Disk Image" buttons {"No", "Re-Name"} default button 2 ¬
    with title "Name Disk Image?")
delay 0.1

if button returned of theName is "Re-Name" then
    set theName to text returned of theName
else
    set theName to "New Encrypted Disk Image"
end if

tell application "Finder"
    if exists of alias ((destinationFolder as text) & theName) then ¬
        delete alias ((destinationFolder as text) & theName)
    set tempFolder to (make new folder at destinationFolder ¬
        with properties {name:theName}) as alias
    set theFiles to selection as alias list
    duplicate theFiles to tempFolder
    set theContainer to POSIX path of (container of tempFolder as alias)
    set filesWithTheName to count of (items of (container of tempFolder as alias) ¬
        whose name contains theName and name extension is "dmg")
    if filesWithTheName is greater than 0 then ¬
        set theName to theName & filesWithTheName + 1
end tell

set theDMG to do shell script "printf  \"" & myPassword & "\" |  hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & POSIX path of tempFolder & "' '" & theContainer & theName & "'"

tell application "Finder" to delete tempFolder

set theOffset to offset of "/" in theDMG
set theDMG to POSIX file (text theOffset thru -1 of theDMG) as alias

tell application "Finder" to set newName to name of theDMG

if deleteOriginals is "Yes" then
    tell application "Finder" to delete theFiles
end if

tell application "Finder"
    activate
    reveal theDMG
end tell

script failedPassVerify
    activate
    display dialog ¬
        "You Have Unsuccessfully Verified Your Password 3 Times In A Row... Please Try Again Later" buttons {"OK"} default button "OK" with title ¬
        "UNSUCCESSFUL PASSWORD VERIFICATION" with icon 0 giving up after 10
    quit me
end script

script setPassword
    set theCount to 0
    repeat until isTrue = true
        activate
        set myPassword to text returned of (display dialog ¬
            ("ENTER THE PASSWORD TO ENCRYPT DISK IMAGE: " & theName) ¬
                default answer "" with hidden answer)
        activate
        set myPassword2 to text returned of (display dialog ¬
            "PLEASE VERIFY YOUR PASSWORD" default answer "" with hidden answer)
        set isTrue to myPassword2 = myPassword
        if isTrue = false then
            set theCount to theCount + 1
            if theCount = 3 then run my failedPassVerify
            activate
            display alert "PASSWORDS DO NOT MATCH" message ¬
                "PASSWORDS DO NOT MATCH" giving up after 3
        end if
    end repeat
    set theCount to 0
    set isTrue to missing value
end script
  1. Open Automator
  2. Make a new Quick Action
  3. Make sure it receives 'files or folders' from Finder.app
  4. Select Run Apple Script and copy/paste in the code
  5. Save it as "New Encrypted Disk Image"
0

I'd like to share an apple script, putting different solutions together I found earlier:

set display_text to "Please enter your password:"
repeat
    considering case
        set init_pass to text returned of (display dialog display_text default answer "" with hidden answer)
        set final_pass to text returned of (display dialog "Please verify your password below." buttons {"OK"} default button 1 default answer "" with hidden answer)
        if (final_pass = init_pass) then
            exit repeat
        else
            set display_text to "Mismatching passwords, please try again"
        end if
    end considering
end repeat

tell application "Finder"
    set theItems to selection
    set theItem to (item 1 of theItems) as alias
    set itemPath to quoted form of POSIX path of theItem
    set fileName to name of theItem
    set theFolder to POSIX path of (container of theItem as alias)
    set zipFile to quoted form of (fileName & ".zip")
    do shell script "cd '" & theFolder & "'; zip -x .DS_Store -r0 -P '" & final_pass & "' " & zipFile & " ./'" & fileName & "'"
end tell
  1. Open Automator
  2. Make a new Quick Action
  3. Make sure it receives 'files or folders' from Finder.app
  4. Select Run Apple Script and copy/paste in the code
  5. Save it as "Make password protected ZIP"

Now you can select any file(s) and/or folder(s) in the Finder app and by right-klicking choose "Quick Action" -> "Make password protected ZIP". Voila!

  • Did you test your code? With multiple files selected in Finder, the only file that gets added to the created zip file, is the file that the zip folder is named after. Also, the do shell script command is a Standard Additions command. It should not be included within the Finder tell block. – wch1zpink Sep 30 at 1:28

You must log in to answer this question.

protected by Community Nov 1 at 11:36

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .