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

10.4: List contents of .zip archives with Automator Apps
After writing this hint about testing .zip archives with Automator, I realized I could create a similar workflow to view the contents of an archive without having to decompress it.

This workflow creates a list of files contained within a .zip archive (along with file size in bytes and modification date and time). It then saves the list to a text file and opens the file for viewing. It also filters out the files contained within an invisible __MACOSX directory (including all the files with a ._ at the beginning), as they clutter the list and I am not interested in those items.

To create the workflow, open Automator and add the following actions, in the order shown:
  1. Finder Library -> Get Selected Finder Items.
  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 -l "$@". The -l flag tells unzip to list the contents of the archive without actually decompressing it.
  3. TextEdit Library -> Filter Paragraphs. Set the 'Return paragraphs that' pop-up to do not contain, and enter __MACOSX in the text box. (This step is optional; it will remove the invisible ._ files from your list.)
  4. TextEdit Library -> New Text File. I set 'Save as' to Temp Archive List.txt and 'Where' to Desktop. Alternatively, you could select 'Show Action When Run' under 'Options' to specify the file name and/or location when the workflow runs.
  5. Finder Library -> Open Finder Items. Leave the 'Open with' pop-up set to Default Application, or set it to your preferred text editor.
To use the workflow, save it as a plug-in for Finder (I saved mine as List Archive Contents). Then, when you need to know what files are in a .zip archive, but do not want to decompress it, just control-click (or right-click) on the archive and select Automator -> List Archive Contents from the contextual menu.

One thing to note: If you have filtered out the files in the __MACOSX directory, as I describe, the number of files listed will differ from the total given at the bottom of the list.
    •    
  • Currently 1.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[13,396 views]  

10.4: List contents of .zip archives with Automator | 14 comments | Create New Account
Click here to return to the '10.4: List contents of .zip archives with Automator' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: List contents of .zip archives with Automator
Authored by: Mbodwin on Aug 01, '06 08:01:10AM

I just right click on the archive. The contextual menu will have the name of the archive at the bottom and you can drill into the archive and see what it contains.



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: JoolsG4 on Aug 01, '06 08:24:13AM

Right-click drill-down doesn't work for me on 10.4.7.

Are you sure you haven't installed some third-party app that gives you this functionality?

---
http://mobile.feisar.com/ - Apple Mac, iSync & Sony Ericsson Hints & Tips



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: madamov on Aug 11, '06 05:29:28AM
You have some third-party utility that is doing this. I am using Springy (www.springyarchiver.com) and its Finder contextual menu. It is a bit slower than StuffIt CM initially opening the contents in CM popup menu, but afterwards it is ok.

[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: benbean on Aug 01, '06 08:47:49AM

For some reason my resulting text file is coming up in all Chinese characters. If I change the "New Text File" component of the Automation to "New TextEdit Document" I get the correct unzip -l output, but it is in a non-fixed-width font and not the usual fixed-width font I have set as default in TextPad (I have TextPad set to Plain Text by default). If I type text immediately after the unzip -l output in the new document, it comes out in the correct fixed default font.

Anybody have any ideas?



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: tj2001 on Aug 01, '06 09:47:54AM

Any possible way to modify this workflow to have it list the file sizes in kbs or Mbs instead of bytes?

---
www.macdynamix.com ---
:: Super Me I Am ::



[ Reply to This | # ]
conversion of file size
Authored by: jvr on Aug 01, '06 03:26:19PM

I briefly considered trying to do that, but I'm not quite sure how to parse the output before applying an equation to convert the units. Since my main goal was to see the file names, I did not pursue this idea any further. But if anyone else wants to tackle the problem, I would love to see the solution.



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: xyz3 on Aug 01, '06 10:38:21AM

Most likely Stuffit Deluxe is adding the contextual menu for browsing archives. I think it's a Menu Options pref..



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: peterwor on Aug 01, '06 04:44:43PM

BIZARRE! When I invoke this automator action I get a textedit (or even Textwrangler) display with 'foreign' (as in japanees or gibberish). Even when I try and display the file in another application, except PathFinder the contents aren't ASCII. Has anyone else seen this? Do I have some issue with my deafult character set?
Any help ?

TIA,
Peter



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: jvr on Aug 01, '06 06:25:48PM

That's odd. You're the second person that has mentioned a problem like this. The only thing I can think of to check would be to look under TextEdit -> Preferences, and see what font is set as default for plain text files.



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: KeithGarner on Aug 02, '06 09:01:08AM

I'm also getting the chinese giberish. I tweaked the preferces for TextEdit to make the default text files and the encoding of text files to be Western-1. However, I'm still getting the giverish. Jumping to the command line I see:

kgarner@oracle [666]:file Temp Archive List.txt
Temp Archive List.txt: Little-endian UTF-16 Unicode character data, with very long lines, with no line terminators

That is not what i changed the default too, and even if it was, I would assume TextEdit should be able to read back in what it wrote. I'm a bit stymied as to what the problem could be. I'd like to use this method as this is the prefered way to do it. However, I found a work around.

Steps 1 and 2 are mostly the same as above, except you change #2 to: /usr/local/bin/als "$@" > ~/Desktop/Temp Archive List.txt Step three then becomes "Finder > Get Specified Finder Items" and you tell it the Temp Archive.txt file. The final step of open with the default application is the same.

Another change I made (but I tested with your original unzip -l) was to use atool which makes this this automation more useful as the atools recognize a large amount of archive formats.

(And yes, that was really the 666th command of that shell, I honestly didn't doctor that.)



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: dan55304 on Aug 02, '06 07:41:47AM

I have asian test also



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: magnamous on Aug 02, '06 02:15:01PM

The problem might be in TextEdit's preferences. I had that problem once when I had TextEdit set to force plain text files to open as UTF-8 instead of an automatically-chosen encoding. You might try changing the setting to automatic. To do it, hit command-comma in TextEdit, choose the "Open and Save" tab, and under the heading that says "Plain text file encoding", choose "Automatic" for the item marked "Opening files:"

If your setting is already marked "Automatic" then try clicking the item in the list called "Customize Encodings List..." and choose the one marked "Western (ASCII)". Perhaps then the results will show up correctly.

Just FYI, though: generally it's best to keep the setting on Automatic. Otherwise, plain text files in other encodings won't show correctly. If yours doesn't work on Automatic, I have no idea what the problem might be.



[ Reply to This | # ]
text is path only
Authored by: leisuremonkey on Aug 01, '06 06:56:58PM

Unlike others, my text is in english, but it doesn't display the contents of the archive, it only displays the file path and file name. I am assuming my error is in step #2, but I don't know enough about shell scripts to troubleshoot.



[ Reply to This | # ]
10.4: List contents of .zip archives with Automator
Authored by: nicksay on Aug 03, '06 11:55:20AM
This workflow can be condensed, if you like, by using a shell script to do the task. Follow steps 1 and 2, but for step 2, use the following code for the command:
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
fi; done
That will filter out the ._ files from the list (and remove the inaccurate file count from the bottom. If you want the ._ files in the list, use the following instead:
for f in "$@"; do
    [[ $f == *.zip ]] && unzip -l "$f" | open -f
done
You do not need the remaining steps of original hint.

[ Reply to This | # ]