Look inside zip files

4 March 2013, 09:00

Ever wanted to see what was in a zip before you unzipped it? The unzip -l command-line tool lets you do this, but nobody really wants to use Terminal each time.

However, you can very quickly create a right-click menu option that will show the contents of a zip in a web browser window. It’s a little rough and ready, but it works fine. Here’s how it’s done:

1. Open Automator, which you’ll find in the Applications list of Finder.
2. In the Choose A Type page, select Service — its icon is that of a cog.
3. In the Search field near the top left, type Filter Finder Items. This will filter the list beneath to just a single item — Filter Finder Item — which you should drag and drop on the right of the program window over the text “Drag Actions or Files Here To Build Your Workflow”.
4. At the top right of the window change the Service Receives Selected dropdown list to read Files or Folders and change the dropdown alongside this to read Finder.app, rather than Any Application.
5. In the search box, type Run Shell Script. Again, this will filter the list beneath to just one item, which you should drag and drop on the right of the program window but beneath the entry you added earlier.
6. In the new section you’ve added, change the Pass Input dropdown to read As Arguments.
7. In the text area beneath this, which starts with “for f in “$@”“, delete everything there and then copy and paste-in the following:

for f in "$@"; do if [[ $f == *.zip ]]; then
    a=$(unzip -l "$f" | fgrep -v __MACOSX)
    n=$(echo "$a" | wc -l)
    echo "$a" | head -n $(( n - 2 )) | open -f -a Safari
fi; done
for f in "$@"; do if [[ $f != *.zip ]]; then
osascript -e 'tell app "Finder" to display dialog "File is not a zip!" default button 1 buttons {"OK"}' 
fi; done

This will show the file listing in Safari. If you use Google Chrome change the fourth line so it ends not with Safari but “Google Chrome” (including the quotation marks). If using Firefox, change Safari to Firefox. If you wanted the results to appear in a TextEdit document you could type TextEdit instead.

8. Click File → Save, then type a name. This is what will appear on the right-click menu, so type something like Look inside zip.

Close Automator and give your new creation a try — right-click a zip file, and select Look Inside Zip. Note that the option might be on a submenu headed Services. You can close the new browser tab when you’ve finished with it.

This way of showing zip contents isn’t exactly elegant. If you know of a better way then be sure to explain in the comments below but remember — we’re trying to keep things as simple as possible, and make use of OS X’s in-built software wherever possible!

To delete your new creation at a later date, open Finder, hit Shift+Command+G, and type the following:


Then drag the file to the trash. The file will have a .workflow file extension.

Know better?

your_ip_is_blacklisted_by zen.spamhaus.org