Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Test .zip archives in the Finder with Automator Apps
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:
  1. Finder Library -> Get Selected Finder Items Action.
  2. 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.
  3. 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.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,209 views]  

10.4: Test .zip archives in the Finder with Automator | 14 comments | Create New Account
Click here to return to the '10.4: Test .zip archives in the Finder with Automator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Why not create the archive at the same time?
Authored by: stevebr on Jul 27, '06 08:44:45AM

To create the archive in the same workflow, insert the Finder action "Create Archive" between your #1 and #2 steps.

Tip: Open up its options and tick show action when run, enabling "Save As" and "Where" for control over the archive name and folder.

Or have two workflows: one as posted in the original hint and another "Archive and Test" as described here.



[ Reply to This | # ]
Why not create the archive at the same time?
Authored by: variante9 on Jul 27, '06 10:15:12AM

This should be useful if it is possible to replace the contextual command (not burried in the second level). Don't know how to to this.



[ Reply to This | # ]
Other options
Authored by: jecwobble on Jul 27, '06 12:48:33PM
Since the main trick of the hint is to use unzip -tq, you could easily do this with OnMyCommand as a "root level" context menu option (i.e. not burried in a second level). You could also kick it off with your favorite "launch whatever" app (Butler, iKey, LaunchBar, etc.), bypassing context menus altogether.

[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: turkchgo on Jul 27, '06 12:42:16PM
"As one who works from home as an animator and video editor, "

I don't get why someone who works with large video and image files would need to make use of a zip utility considering it does nothing but maybe shave a few kilobits of metadata off the files?

The only reason I can think of is to make a single file out of many small ones?

Zip and Stuffit have little to no effect on video, audio or image data. They do make nice single file packages out of say 20 photos.

But zipping a 500Mb or 1Gb DV or MPEG file is just a waste of CPU cycles on both ends.

[ Reply to This | # ]

10.4: Test .zip archives in the Finder with Automator
Authored by: osxpounder on Jul 27, '06 01:24:29PM

As a person who does similar work, I'd be interested to see a reply to that question, too: why bother zipping a file that won't compress much?

I can think of a few reasons, but I won't second-guess your motives. I'm interested in what you think. I'll just point out that a ZIP can keep relative folder and file locations intact, in case your project relies on such things. I think sometimes OSX has trouble unzipping files that contains 2 or more folders of the same name, but can't reproduce the problem right now, so I'm not even sure I remember that right.



[ Reply to This | # ]
Compression varies depending on codec
Authored by: jvr on Jul 28, '06 09:00:56AM

I send & receive QuickTime movies rendered in a variety of codecs, and the level of compression accomplished by zip does vary, depending on the codec used. Yes, there are some codecs for which zip is not helpful, but there are others for which it cuts the file size nearly in half.

Example:
A 15 second logo animation with alpha channel, 720 x 486, 29.97 fps, 32-bit Animation codec.
Before zip: 199 MB
After zip: 122 MB

That's enough compression to save a significant amount of time on upload over my cable connection.



[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: cbenedict on Jul 27, '06 12:55:16PM

Could please post a screen shot of your Shell Script. I received a message posted to the log file that I have this error message.
error-:-c: line : syntax error near unexpected token 'tq'

Workflow execution failed.

Any suggestions.





[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: jvr on Jul 28, '06 09:41:38AM

I can't post a screenshot at the moment. If you enter the script exactly as stated in the hint, it should work fine. Make sure you use a hyphen in front of the "tq."



[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: xwiz on Jul 27, '06 04:54:11PM

I don't understand why your mac is creating invalid archives. Normally, I archive stuff and it's fine. Why are you having a problem?

Are you saying we can't trust the archive option from the Finder?



[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: jvr on Jul 28, '06 09:36:39AM

I can't explain why this has happened, and I can't reproduce it, but it has happened. In each case, zipping the file again yielded a valid archive. Go figure.



[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: rjetton on Jul 27, '06 05:21:37PM

I agree. The time spent trying to compress these media files is probably a lot more than the few seconds saved in their file transfer.

Have you considered using tar (without compression)? It preserves relative file pathnames like zip, and is very fast compared to zip.



[ Reply to This | # ]
10.4: Test .zip archives in the Finder with Automator
Authored by: qwerty denzel on Jul 28, '06 12:15:22AM

Or create a disk image using disk utility? It's probably not as fast as tar, but is nonetheless very useful, and quite easy to make.



[ Reply to This | # ]
why zip?
Authored by: ngb on Jul 31, '06 02:55:48PM

I think zip is slightly more universal than tar, in terms of distributing an archive to both Mac and PC users. I can appreciate the need to send files organized as an archive, rather than willy-nilly, even if there is no siginicant space savings.



[ Reply to This | # ]
Zipping uncompressed video
Authored by: BeezelNut RaRa on Jul 28, '06 03:26:10AM

If the video is in an uncompressed format, zipping it cuts the file size in half.

90s uncompressed video = 1.85GB
After zipping = 988MB



[ Reply to This | # ]