Nu även som droplet. Fördelen med det är att den kan packa både filer och mappar samtidigt.
property myVersion : "1.2"
property myButton : 3
on run
activate
set myDialog to display dialog "Zippa, version " & myVersion buttons {"Avbryt", "Dra och släpp", "Lista"} default button 3 cancel button 1 with icon 1
if button returned of myDialog is "Lista" then
set myChoice to (choose from list {"Filer, behåll källa", "Filer, radera källa", "Mappar, behåll källa", "Mappar, radera källa"} with prompt "Vad ska packas?")
if class of myChoice is boolean then
return
end if
if "filer" is in item 1 of myChoice then
set theObjects to (choose file with multiple selections allowed)
else
set theObjects to (choose folder with multiple selections allowed)
end if
my doScript(theObjects, item 1 of myChoice)
end if
end run
on open (theObjects)
activate
set myChoice to display dialog "Zippa, version " & myVersion & return & return & "Ska källan behållas eller raderas?" buttons {"Avbryt", "Radera", "Behåll"} default button myButton with icon 1 giving up after 2
if gave up of myChoice is true then
return
else
set myButton to button returned of myChoice
set B to button returned of myChoice
end if
my doScript(theObjects, B)
end open
on doScript(theObjects, myChoice)
if "radera" is in myChoice then
set myDeleteSource to true
else
set myDeleteSource to false
end if
set output to {}
set SkippedItems to {} -- this will be a list of skipped items
set DestinationFolder to missing value -- a Finder path to a destination folder if different
repeat with SomeItem in the theObjects -- step through each item in the theObjects
try
set SomeItem to SomeItem as text
if the last character of SomeItem is in {":", "/"} then set SomeItem to text 1 thru -2 of SomeItem
set ArchiveSource to POSIX path of SomeItem
if DestinationFolder is missing value then -- save the archive to the same location
set ArchiveName to ArchiveSource & ".zip"
else -- save the archive to the specified folder
set TheName to name of (info for SomeItem as alias)
set ArchiveName to (POSIX path of DestinationFolder) & TheName & ".zip"
end if
do shell script "ditto -ck " & (quoted form of ArchiveSource) & space & (quoted form of ArchiveName)
if myDeleteSource is true then do shell script "rm -r " & (quoted form of ArchiveSource)
set the end of the output to (POSIX file ArchiveName) as alias -- success
on error ErrorMessage number ErrorNumber
log ErrorMessage
set the end of SkippedItems to SomeItem
end try
end repeat
if SkippedItems is not {} then -- handle skipped items
set TheCount to (count SkippedItems) as text
display alert "Error with Archive action" message TheCount & " items(s) were skipped."
(*
choose from list SkippedItems with title "Error with Archive action" with prompt "The following items were skipped:" with empty selection allowed
if result is false then error number -128 -- user cancelled
*)
end if
return the output -- pass the result(s) to the next action
-- end run
end doScript