Compress folders into separate archives
Sometimes a solution is simpler than you think it’s going to be. I was trying to figure out a way to write a shortcut to take a folder and have all of its sub-folders compressed into individual archives—i.e., one archive per folder. Alas, selecting them in the Finder and choosing Compress turns all your folders into one big archive.1
As easy as this feels like it should be, Shortcuts was thwarting me. I wrote a workflow that seemed like it ought to be fine, and it did nothing. I could have fallen back to a shell script, but I’ll be honest, I was feeling stubborn.
So I hit the old search engine and found this post by Lukas Polak, which from its description seemed like it should work, even if I didn’t really understand why.
Sure enough, it does. The secret is in opening the Archive Utility app, which is the macOS program that handles compressing/expanding files—yes, there’s actually a whole app with an interface! Drag the folders onto that app icon in the Dock and it will, by default, compress them into individual archives. You may also want to change the compression format to ZIP—the default, compressed archive, is a .cpgz file, though that’s more a matter of personal preference—the behavior is the same.
While I wish this was easier to do in Shortcuts, I’m gratified that there was a pretty simple way to do it with no scripting at all. Always a nice discovery.
- Weirdly enough, if you hold down option while bringing up the contextual menu, it changes the text from “Compress” to “Compress X items”…but the end result is the same: one archive for everything you select. I’m not even sure why it changes the text—perhaps it’s a bug? ↩