MacMusic  |  PcMusic  |  440 Software  |  440 Forums  |  440TV  |  Zicos
file
Search

View Zip File Contents With a Shortcut on a Mac

Tuesday November 29, 2022. 05:00 PM , from MacMost
While the Mac Finder handles zipping and unzipping files just fine, it fails to give you any way to see the contents of a ZIP file. You can use some Terminal commands to do this. Better still, you can use those Terminal commands in a Shortcut to make it easy.



Check out View Zip File Contents With a Shortcut on a Mac at YouTube for closed captioning and more options.
Video Transcript: Hi, this is Gary with MacMost.com. Let me show you how you can view the contents of a zip file on your Mac.
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to MacMost.com/patreon. There you can read more about the Patreon Campaign. Join us and get exclusive content and course discounts.
Now while macOS allows you to easily unzip files and to create new zip files there is no easy way to view the contents of a zip file without extracting everything from it. Now there are third party apps that will do this. But you can actually do it using the Terminal on your Mac. As you can do it in the Terminal you can take those terminal commands and use those in a shortcut to make it easy to do.
So starting off here I've got two example of zip files here. I'm going to use the Terminal to see what is inside them. So I'm going to use Spotlight and launch the Terminal. Then there are many different ways to read the contents here. One is to use a utility called zipinfo. With Zip Info all you need to do is have that command then put the file after it. You don't have to type the entire path here. I can just drag and drop from the Finder into Terminal and it will type the path for me. Now I just hit Return here and the simple command will give me a list of everything in the Zip File. It will even tell me the number of bytes in the file and date information. At the bottom it shows me the total the number of bytes, uncompressed, and the number of bytes compressed and the amount that zipping it all together saved.
In a case like this the files are probably zipped together to easy transport. Not necessarily to save space.
Now another way to do this is to use the Unzip command which is what you would normally use to unzip a file in the Terminal. There's really no need to use that as I could just double click on this file and it will unzip in the Finder. No Terminal needed. But, if I use unzip with the dash L parameter and then I drag the file in, press Return, it will list the contents instead of extracting them. You could see I get a nice list here. I get the size and the date, as before, and the name of the file. I think it looks a lot better. Unfortunately it doesn't include that nice summary information at the bottom. But I'm going to go with this as the command we're going to use in Shortcuts.
So in the Shortcuts App I'm going to create a New Shortcut. I'm going to call this View Zip Contents. I'm going to add an Action for executing a Shell Script. Now it comes with some sample code in there. We don't need that. Instead you want to use that Unzip command dash L. Now we want to add the path of the zip file. Now what we want to do is pass that in as a parameter. So here we've got your Input and we can change that to be shortcut input. Now we get at the top these parameters we can set. Receive Any. We don't want any. We just want Files. So we will change that there. Input From we will change it. If I click there you can see it goes to the information here on the right with the details. I'll say, let's use this as a Quick Action so we can right click on the file and access this shortcut. So now the input comes in here. We're going to use the input as Arguments. That allows us to do dollar sign 1 as the first argument. So a file comes in here and it gets passed in here and replaces this.
One more thing I want to do here is change, if there is no input, to Ask For. Have it Ask For files. We can still run this shortcut all by itself and that will just prompt us to select a file. After it runs this Shell Script it's going to have the output here. We need to see it. One of the many ways we can see it is by using the Quick Look action right there. It will Shell Script results in Quick Look. So it will just come up in a temporary window. So now that we've got this added here let's give it a try. So if we want to use it on this file here normally I would Control Click on it, right click or two-finger click on a trackpad, and then normally it would be under Quick Actions. But it's not because I need to customize first. It will take me into System Settings all the way down into Extensions in the window where I can select Quick Actions to show in the Finder. So I need to scroll down here and find this. I'll select it and now it should appear in that list. So let's try it again. This time when I go to Quick Actions there it is. Now I can select it. It's going to run that Shell Script and it's going to produce the output here.
So, so far so good. But there are two modifications I want to make. First, if I try it with this file instead of the second file and I use the same thing look at what I get. I'm going to get a bunch of files here, like this one, and this one, and this one. These are hidden files that the Mac Finder uses but you usually don't see. When I zipped up this folder it took those files with into the Zip File. If I were to unzip I wouldn't see them They would be invisible. So it would be nice not to have one for every real file that is there.
So back here in Terminal if I use unzip-L and I include the file there, like that, I could now pipe that into another Shell command. So I'm going to use the pipe character that is right above the Return key on US keyboards and I'm going to pipe it into grep, which is the way to process text. I'm going to say dash V to exclude and then in quotes I'm going to exclude any lines that have certain characters. This takes two underscores and MACOSX, like that. Any line that has got that in it just exclude it. Now if I run this now you could see it excludes those. It only has the real files that are there. So let's take this and add it into our script here. So now with that modification we can try the shortcut again. Quick Actions use contents. The results will be just the real files.
Now remember how I said I would like to have the summary when we used the zip info command. Well, it turns out there is a way to get just that. If you do zipinfo and then dash t as the parameter and then bring in the file there. We run it and we see the number of files, bytes uncompress, bytes compressed, amount saved. Now there is no reason we can't use this in the same Shell Script that we're using in the Shortcut. So in the very next line here I'm going to do Zipinfo and then dash t, and then use the same parameter, dollar sign 1. That should give us that line of info right after we get the list. Now when we try this we'll see the results of both commands. Here we've got the list coming from unzip-L and here we have the summary line from zipinfo-t. Now you've got a great way to see the content of any zip file by just using this Quick Action in the Finder.
If you want to run it all by itself either here in Shortcuts or maybe have it in the Pin Menu there you can run it and since it didn't find any Input it's going to prompt you for input. You can select a file and get the info from that zip file. I hope you found this useful. Thanks for watching. Related Subjects: Shortcuts (40 videos), Terminal (36 videos)
Related Video Tutorials:
How To Resize Photos With a Shortcut On Your iPhone or iPad ― Building a Mac Shortcut To Add a Border And Caption To a Photo ― Create an iPhone Shortcut To Show Your Vaccination Card ― How To Create a Keyboard Shortcut To Open a File In a Specific App
https://macmost.com/view-zip-file-contents-with-a-shortcut-on-a-mac.html
News copyright owned by their original publishers | Copyright © 2004 - 2024 Zicos / 440Network
Current Date
Mar, Fri 29 - 01:46 CET