10.4: Test .zip archives in the Finder with Automator
Jul 27, '06 07:30:06AM
Contributed by: jvr
As one who works from home as an animator and video editor, I make regular use of the Create Archive contextual menu item in the Finder to compress large files before transferring them over the internet. More than once, I have taken the time to transfer files of 1GB or more, only to discover that the archives are somehow incomplete and cannot be decompressed on the other end.
To avoid this setback, I learned how to test .zip archives in Terminal prior to sending them off (via unzip -tq). However, I wanted to streamline this process, avoiding unnecessary typing on the command line. So, I created an Automator workflow to do the job, and saved it as a Finder plug-in for simple contextual menu access.
To create the workflow, open Automator and add the following actions, in the order shown:
- Finder Library -> Get Selected Finder Items Action.
- Automator Library -> Run Shell Script. Set the Shell pop-up to /bin/bash, the Pass Input pop-up to as arguments, and the actual command to unzip -tq "$@". The -t flag tells unzip to test the archive without actually writing the decompressed files to disk. The -q flag tells it to suppress all output messages, except for the final result.
- Automator Library -> Run AppleScript. Insert this code:
on run {testResult}
tell application "Finder"
display dialog testResult buttons {"OK"} default button 1
end tell
end run
This will display a dialog box in the Finder that displays the result of the test.
When the workflow runs, the message you hope to see is No errors detected in compressed data of [filename].zip.. If there is a problem with the archive, some kind of error will be reported, and you will need to delete that .zip file and try archiving the desired file again.
To use the workflow, save it as a plug-in for Finder (I saved mine as Test Archive). Then all you have to do to test a .zip archive is control-click on the archive and select Automator -> Test Archive from the contextual menu.
My solution is pretty simple, but it does what I want it to. One downside I see is that there is no progress bar to tell you that the computer is working while the test is being conducted -- it works completely in the background until it finishes and displays the Finder dialog. I just look for an increase in my CPU usage in the MenuMeters graph to see that the test is in progress.
Now I know for sure that I am sending valid archives before starting a massive upload.
Comments (14)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060724125523873