Something about the way files are zipped when using Finder’s “Create Archive” contextual menu item causes problems with my web hosting provider. Because of these problems, I have taken to using the UNIX zip tool instead.
If you find yourself needing an AppleScript way of using zip, then you can use this as a starting point:
on run
display dialog "Choose file or folders?" buttons {"Cancel", "Folders", "File"} default button 3 with icon note
if button returned of result is "File" then
choose file with prompt "Create ZIP file of this file:" without invisibles
get {result}
else
choose folder with prompt "Create ZIP files of these folders:" with multiple selections allowed
end if
open result
end run
on open droppedItems
set ASTID to AppleScript's text item delimiters
repeat with sourceFile in droppedItems
set {sourceName, sourceExtension, sourceIsFolder} to {name, name extension, folder} of (info for sourceFile without size)
set sourceFile to sourceFile as Unicode text
set AppleScript's text item delimiters to {":"}
if sourceIsFolder then
set sourceParent to POSIX path of (text 1 thru text item -3 of sourceFile)
set recursive to "r"
get sourceName
else
set sourceParent to POSIX path of (text 1 thru text item -2 of sourceFile)
set recursive to ""
end if
-- Remove extension from sourceName
set AppleScript's text item delimiters to {"."}
try
get text 1 thru text item -2 of sourceName
on error
get sourceName
end try
do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().replace(' ','_').encode('utf8')\" " & quoted form of result
if sourceExtension is in {"applescript", "scpt", "scptd", "app"} then
get result & "_"
else if sourceExtension is "dmg" then
get result & ".dmg.zip"
else
get result & ".zip"
end if
-- Get path to zip file
choose file name with prompt "Save zip file as:" default name (result)
get result as Unicode text
if (text -4 through -1 of result) is not ".zip" then
set zipFile to POSIX path of result & ".zip"
else
set zipFile to POSIX path of result
end if
try
do shell script "cd " & quoted form of sourceParent & "; /usr/bin/zip -qo9" & recursive & space & quoted form of zipFile & space & quoted form of sourceName
on error errMsg number errNum
set AppleScript's text item delimiters to ASTID
display alert "Error while creating ZIP file. (" & errNum & ")" message errMsg buttons {"Cancel"} default button 1
error number -128
end try
end repeat
beep 2
set AppleScript's text item delimiters to ASTID
end open