Use a build script to slim down your zip files

Hidden files and directories can be a real problem for add-on developers or anyone trying to package their work in a zip file. This is especially a problem on Macs with the dreaded .DS_Store hidden directory. Here’s a tweet from Ryan Masuga of Devot:ee reminding Mac developers to keep their zip archives clean:

How much does .DS_Store take up? Well in early versions of PDF Press I realized that by accidentally including .DS_Store in my archive I was making my customer download an extra 1MB of data they didn’t need (and making Devot:ee store an extra 1MB, sorry Ryan)!

So we can all agree .DS_Store and other hidden files and directories in zip archives are bad. However operating systems suck at giving us the ability to avoid including hidden files, especially if you’re trying to zip up an entire directory. Usually your only option is to use the command line and zip your directories manually, carefully excluding hidden files. Here’s the terminal command I have to run in order to package PDF Press.


$> zip -r zips/pdf_press_.zip LICENSE.txt README.md docs system themes --exclude=*.DS_Store*

Ugh, that’s a lot to remember. I also have to run a separate command to package the 5-site license (same directories, just a different license file). As you can imagine, trying to remember this command every two months between releases is a huge pain. And if you’ve read my post on using Terminal Aliases, you know I’m always looking for shortcuts to long commands.

Ideally one simple easy to remember command I could run that could package the two versions of PDF Press correctly every time. Luckily it’s pretty easy with a little bash shell scripting to create a build script to package PDF Press for me.

First I create a text file called “build.sh” in my text editor:

Next I save the file to my repository for PDF Press. Now to make the script executable I run the following command in Terminal in the directory containing the build script.


$> chmod u+rwx build.sh

Finally to execute the script I just run the following command in Terminal


$> ./bash.sh

running the build script

Once the zip commands have finished executing there are two new zip files in the “zip” folder in the directory for PDF Press ready to be renamed to include the version and uploaded to Devot:ee or my Gumroad store.

Even if you don’t sell add-ons or plugins, there are probably times where you have to zip up your work and send it off to client. You could easily use this technique to save them some precious bytes. What’s more, once you create the script you can adapt it to any project.