Polymathic

Digital transformation, higher education, innovation, technology, professional skills, management, and strategy


On a Mac, how do I programatically compress each folder in a folder?

As part of cleaning out some old drive storage, I needed to zip a folder of folders. I could, of course, do this by hand, but it was a lot of folders and would be rather tedious. Instead of doing that for 10 minutes, I took 2 hours to figure out an automated solution!

I tried Forklift, Automator, Shortcuts, and Pathfinder. Nothing could do it; at least I couldn’t find a way to do it. After some searching, I found partial solutions in AppleScript. Here’s what I came up that solved my problem.

tell application “Finder"
set theFolders to selection
repeat with aFolder in theFolders
set theItem to aFolder as alias set itemPath to quoted form of POSIX path of theItem set fileName to name of theItem set theFolder to POSIX path of (container of theItem as alias) set zipFile to quoted form of (fileName & ".zip") do shell script "(cd " & quoted form of theFolder & " && zip -r " & zipFile & " " & quoted form of fileName & ")" end repeat end tell

A key feature of this solution is that it doesn’t create an archive with the full pathname. The zip file contains only the folder name and “down”.


Discover more from Polymathic

Subscribe to get the latest posts sent to your email.



Leave a Reply

Your email address will not be published. Required fields are marked *

About Me

Visionary leader driving digital transformation across higher education and Fortune 500 companies. Pioneered AI integration at Emory University, including GenAI and AI agents, while spearheading faculty information systems and student entrepreneurship initiatives. Led crisis management during pandemic, transitioning 200+ courses online and revitalizing continuing education through AI-driven improvements. Designed, built, and launched the Emory Center for Innovation. Combines Ph.D. in Philosophy with deep tech expertise to navigate ethical implications of emerging technologies. International experience includes DAAD fellowship in Germany. Proven track record in thought leadership, workforce development, and driving profitability in diverse sectors.

Favorite sites

  • Daring Fireball

Favorite podcasts

  • Manager Tools

Newsletter

Newsletter