on run (input, parameters)
- Create a PKZip archive of the selected Finder item (s)
- If no destination folder is specified, the archive will be placed in the same location
- Input: a list of Finder items to archive
- Output: a list of Finder items archived
set output to ()
SkippedItems set to () - this will be a list of skipped items
DestinationFolder set to missing value - a Finder path to a destination folder if different
repeat with SomeItem in the input - step through each item in the input
try
SomeItem set to SomeItem as text
if the last character of SomeItem is in {":", "/") then set SomeItem to text 1 through -2 of SomeItem
ArchiveSource set to POSIX path of SomeItem
if DestinationFolder is missing value then - save the archive to the same location
set to ArchiveSource & ArchiveName. "zip"
else - save the archive to the specified folder
TheName set to name of (info for SomeItem as alias)
ArchiveName set to (POSIX path of DestinationFolder) & & TheName. "zip"
end if
do shell script "ditto-ck" & (quoted form of ArchiveSource) & space & (quoted form of ArchiveName)
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
TheCount set to (count SkippedItems) as text
display alert "Error with Archive action" message TheCount & "items (s) were skipped - workflow will continue"
(*
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 canceled
*)
end if
return the output - pass the result (s) to the next action
end run
Bookmarks