Sep 07, '05 08:51:00AM • Contributed by: macventure
So I hacked up this code for the small little archives I create for my website. The code isn't perfect, but I'm sure someone can clean it up and put in some better error trapping.
-- Script name: WinZipMe
-- zip command options: -r = recursive,
-- -j = junk path (similar to Create Archive)
tell application "Finder"
-- Note: There's no extensive error trapping on this script
-- (e.g. folder counts for larger folders to show warnings)
-- You could also take off any .xxx suffix before adding
-- the file to the .zip if needed
set theItem to selection as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (theFolder & fileName & ".zip")
do shell script "zip -r -j " & zipFile & " " & itemPath
-- delay 1 -- this may be needed (and adjusted) for larger folders?
try -- We don't need to say anything if there are no .DS_Store files
do shell script "zip -d " & zipFile & " '*.DS_Store'"
end try
end tell
Wouldn't it be great if holding down the Option key while choosing Create Archive would exclude the special hidden Mac dot files?
[robg adds: If you're running 10.4, you can make this script a Finder plug-in using Automator; then it's just a control-click away with any file or folder selected. Open Automator, click on the Automator Library item, then drag the Run AppleScript action to the work area. Replace the (* Your script goes here *) line with the script above, and use File: Save as Plug-in to create a Finder plug-in (I called mine WinZipper). Select anything in the Finder, control-click, and then choose WinZipper from the Automator sub-menu.]
