here’s another applescript solution to a missing functionality in OS X. inspired by a question on the MacWorld Forums which asks, basically, how do you easily compress multiple folders into multiple zip files? if you try to compress multiple files or folders in the finder you get a single archive containing them all. or you can select and compress each one individually. this can be a pain.
this script is based on one found at stackoverflow. but a couple of additions have been included :
• application saves as a droplet for drag-and-drop functionality
• invisible .DS_Store files are stripped out of the archive
--thanks to tim.g and Matthew H. for basic script : --http://stackoverflow.com/questions/4909337/zip-folder-using-applescript on open TheseItems repeat with thisItem in TheseItems tell application "Finder" set itemPath to quoted form of POSIX path of thisItem set fileName to name of thisItem set theFolder to POSIX path of (container of thisItem as alias) set zipFile to quoted form of (theFolder & fileName & ".zip") do shell script "zip -jr " & zipFile & " " & itemPath & "* -x *.DS_Store" end tell end repeat end open
copy the script into script editor and save it as an application.
or download ZipStuff as a finished app. – thanks to box.net
place the application in your sidebar. drag-and-drop stuff onto it. each individual item, be it folder or file, will be saved as its own zip archive.
easy peasy.
Old? Good ‘eavens, man! I may have a couple of machines around that qualified for the engraving-removal upgrade when that Jobs fellow left the company the first time, but Snowy’s still a cub by comparison! Harrumph!
I set up an experiment, thusly:
I have two folders at root, each has an app, with one of the folders also carrying a file of type text and one of untyped. I can select each in the Finder, context-click and choose Compress, and have Folder’s Name.zip appear underneath, and if I select both before choosing to Compress it yields the expected ‘Archive.zip’ singleton.
And now, the clincher. I dragged both onto the ZipStuff icon that was in plain view on the desktop, and I got this for my effort:
What do you make of that, Holmes?
damn and blast it (sorry can’t do more than that in character).
doesn’t that just give you the screaming squirts (that’s more like me).
the variation without the -j option could go something like this :
tell application "Finder"
set itemPath to quoted form of POSIX path of thisItem
set fileName to name of thisItem
set theFolder to POSIX path of (container of thisItem as alias)
set zipFile to quoted form of (fileName & ".zip")
set theScript to ("cd " & theFolder & "; /usr/bin/zip -r " & zipFile & " " & itemPath & "* -x *.DS_Store")
do shell script theScript
end tell
… and works — except when you unzip it you get a nested folder structure starting at the user level.
i’ll have to do some more research into this when i get a chance.
sorry watson — not so elementary for a beginner like me.
m.
Well, that almost worked.
Dropped a bunch o’ things on and get an error dialog which ends with:
“zip error: Invalid command arguments (cannot repeat names in zip file)”
What next, Holmes?
G’day Watson
The only time I’ve seen that is when there are two files in the same folder with the same name.
eg. “this_file.txt” and “this_file.rtf”
(are you working on an older OS?)
But I would have thought this would also fail if you tried a manual compression.
Have you tried that?
m.