global parentFolder
set selUnixPaths to {}
set tempDir to quoted form of POSIX path of (path to temporary items folder as text)
set itemsUnixPaths to ""
tell application "Finder"
set finderSelection to selection
set parentFolder to (container of (item 1 of finderSelection as alias))
if (length of finderSelection) > 1 then
repeat with selectedItem in finderSelection
copy quoted form of ("./" & (name of (selectedItem as alias))) to end of selUnixPaths
end repeat
repeat with selectedItem in selUnixPaths
if itemsUnixPaths = "" then
set itemsUnixPaths to selectedItem
else
set itemsUnixPaths to itemsUnixPaths & " " & selectedItem
end if
end repeat
set archivename to my checkName("Archive.zip")
else
set itemsUnixPaths to quoted form of ("./" & name of (item 1 of finderSelection as alias))
set namewitoutext to my trimext((item 1 of finderSelection) as alias)
set archivename to my checkName(namewitoutext & ".zip")
end if
end tell
set shellScript to "cd " & quoted form of (POSIX path of (parentFolder as alias)) & "; zip -b " & tempDir & " -9r '" & archivename & "' " & itemsUnixPaths & " -x *.DS_Store"
with timeout of 60 * 60 seconds
do shell script shellScript
end timeout
on trimext(myfile)
tell application "Finder"
set fileextlenght to count of ((name extension of (myfile)) as text)
set fileName to name of (myfile)
end tell
if fileextlenght > 0 then
return (items 1 thru -(fileextlenght + 2) of fileName) as string
else
return fileName
end if
end trimext
on checkName(archiveFile)
tell application "Finder"
if exists file (((parentFolder as alias) as string) & archiveFile) then
set fileName to (items 1 thru -5 of archiveFile)
set x to 2
repeat while exists file (((parentFolder as alias) as string) & archiveFile)
set archiveFile to fileName & " " & x & ".zip"
set x to x + 1
end repeat
end if
return archiveFile
end tell
end checkName