2 votes

Comment créer un fichier ZIP protégé par un mot de passe à partir d'une sélection dans l'application Finder ?

Je voudrais utiliser les "Actions rapides" dans l'application Finder à partir d'une sélection de fichiers et/ou de dossiers pour créer un fichier ZIP protégé par un mot de passe.

2voto

wch1zpink Points 6067

Il ne s'agit pas d'une solution directe, mais elle peut être utilisée comme solution alternative car elle créera un fichier image disque (.dmg) de tous les fichiers et/ou dossiers sélectionnés dans le Finder, qu'il s'agisse d'un seul ou de plusieurs éléments.

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. Ouvrir Automator
  2. Créer une nouvelle action rapide
  3. Assurez-vous qu'il reçoit des "fichiers ou dossiers" de Finder.app.
  4. Sélectionner Exécuter Apple script et copier/coller le code
  5. Enregistrez-la sous le nom de "New Encrypted Disk Image".

1voto

redsky Points 39

Je voudrais partager un script de Apple, mettant ensemble différentes solutions que j'ai trouvées précédemment :

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. Ouvrir Automator
  2. Créer une nouvelle action rapide
  3. Assurez-vous qu'il reçoit des "fichiers ou dossiers" de Finder.app.
  4. Sélectionner Exécuter Apple script et copier/coller le code
  5. Enregistrez-le sous le nom de "Make password protected ZIP".

Maintenant vous pouvez sélectionner n'importe quel(s) fichier(s) et/ou dossier(s) dans l'application Finder et par un clic droit choisir "Action rapide" -> "Créer un ZIP protégé par mot de passe". Et voilà !

LesApples.com

LesApples est une communauté de Apple où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres utilisateurs d'appareils Apple, poser vos propres questions ou résoudre celles des autres.

Powered by:

X