J'ai estimé qu'il y avait suffisamment de différences entre ma solution et l'autre réponse postée, pour proposer ce script comme une autre réponse au post original.
Enregistrer ce script comme une application dans l'app ScriptEditor
Ce script permet à l'utilisateur de déposer plusieurs fichiers ou dossiers, directement sur l'icône de cette application... Et donne également à l'utilisateur l'option de conserver ou de supprimer les fichiers ou dossiers originaux.
Si cette application script est exécutée de manière normale en double-cliquant sur l'application, l'utilisateur a la possibilité de choisir des fichiers uniques ou multiples ou de choisir des dossiers uniques ou multiples, à traiter. En outre, l'utilisateur a la possibilité de supprimer ou de conserver les fichiers originaux.
Ceci a été testé avec la dernière version de MacOS High Sierra.
UPDATE : Ce code a été modifié pour traiter les fichiers ou dossiers qui sont verrouillés.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
global deleteFiles, isTrue, theCount, myPassword, theName
on open theFiles
--HANDLE THE CASE WHERE THE SCRIPT IS LAUNCHED BY DROPPING FILES ONTO APP ICON
repeat with i from 1 to count of theFiles
set thisItem to item i of theFiles
tell application "Finder"
if locked of (get properties of thisItem) then
set locked of thisItem to false
end if
end tell
set isTrue to missing value
set theCount to 0
set theName to missing value
set theFolder to thisItem
tell application "Finder"
set theContainer to container of theFolder as alias
set theName to name of (get properties of theFolder)
end tell
run my setPassword
run my keepOriginals
set myPath to POSIX path of theFolder
set theContainer to POSIX path of theContainer
do shell script "printf \"" & myPassword & "\" | hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
myPath & "' '" & theContainer & theName & "_Encrypted'"
if deleteFiles = true then
tell application "Finder" to delete theFolder
end if
end repeat
end open
on run
--HANDLE THE CASE WHERE THE SCRIPT IS LAUNCHED DROPPED FILES
activate
set theChoice to display dialog ¬
"WOULD YOU LIKE TO CHOOSE FILES OR FOLDERS?" buttons {"Cancel", "Choose Files", "Choose Folders"} ¬
default button ¬
"Choose Folders" cancel button ¬
"Cancel" with title ¬
"Make Your Choice" with icon 1 ¬
giving up after 20
if button returned of theChoice is "Choose Files" then
run my chooseFiles
else if button returned of theChoice is "Choose Folders" then
run my chooseFolders
else if button returned of theChoice is "" then
return
end if
end run
script chooseFiles
activate
set theFiles to (choose file with multiple selections allowed)
repeat with i from 1 to count of theFiles
set thisItem to item i of theFiles
tell application "Finder"
if locked of (get properties of thisItem) then
set locked of thisItem to false
end if
end tell
set isTrue to missing value
set theCount to 0
set theName to missing value
set theFolder to thisItem
tell application "Finder"
set theContainer to container of theFolder as alias
set theName to name of (get properties of theFolder)
end tell
run my setPassword
run my keepOriginals
set myPath to POSIX path of theFolder
set theContainer to POSIX path of theContainer
do shell script "printf \"" & myPassword & "\" | hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
myPath & "' '" & theContainer & theName & "_Encrypted'"
if deleteFiles = true then
tell application "Finder" to delete theFolder
end if
end repeat
end script
script chooseFolders
activate
set theFiles to (choose folder with multiple selections allowed)
repeat with i from 1 to count of theFiles
set thisItem to item i of theFiles
try
tell application "Finder"
set locked of every item of entire contents of thisItem to false
end tell
end try
set isTrue to missing value
set theCount to 0
set theName to missing value
set theFolder to thisItem
tell application "Finder"
set theContainer to container of theFolder as alias
set theName to name of (get properties of theFolder)
end tell
run my setPassword
run my keepOriginals
set myPath to POSIX path of theFolder
set theContainer to POSIX path of theContainer
do shell script "printf \"" & myPassword & "\" | hdiutil create -encryption AES-256 -stdinpass -srcfolder '" & ¬
myPath & "' '" & theContainer & theName & "_Encrypted'"
if deleteFiles = true then
tell application "Finder" to delete theFolder
end if
end repeat
end script
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 keepOriginals
set keepOrDelete to display dialog ¬
("Would You Like To Delete The Original Item... " & theName & "?") buttons {"DELETE ORIGINALS", "KEEP ORIGINALS"} ¬
default button 2 ¬
with title ¬
"KEEP OR DELETE ORIGINALS?" with icon 0 ¬
giving up after 30
if button returned of keepOrDelete is "DELETE ORIGINALS" then
set deleteFiles to true
else if button returned of keepOrDelete is "KEEP ORIGINALS" then
set deleteFiles to false
else if button returned of keepOrDelete is "" then
set deleteFiles to false
end if
end script
script setPassword
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
end if
activate
display alert ¬
"PASSWORDS DO NOT MATCH" message ¬
"PASSWORDS DO NOT MATCH" giving up after 3
end if
end repeat
end script