Sky Blue Sofa Blog How to Compress a Directory in OSX without Extra Files - Sky Blue Sofa Blog

How to Compress a Directory in OSX without Extra Files

Posted by Dave Rogers // February 18, 2014 // in Blog // 0 Comments


In the past, I've used CleanArchiver to zip up my files before I send them out to customers. CleanArchiver is a great utility that removes the .DS_Store files that OSX uses. I recently started using Versions and SVN for source control. One downside of SVN is that it places an .svn folder inside your code and CleanArchiver doesn't remove these folders. Blerg.

As I outlined recently in How I went Paperless with Evernote and OSX, the automator in OSX can be a great tool. I decided to try my hand at it again.

Creating a Compress Service

I created a service that takes files and/or folders as arguments and does something with them. Here's what I did:

  1. Open up Automator on your Mac from Applications > Automator
  2. Click the 'New Document' button
  3. Choose 'Service'
  4. Change the dropdown at the top to read 'Service receives selected folders in any application'
  5. Add the 'Run Shell Script' action from Actions > Library > Utilities or type 'Run Shell Script' in the name search at the top left.
  6. Change the 'Pass Inputs' dropdown to 'as arguments'
  7. In the script box, enter this text:
    for folder in "$@"
    directory="$(dirname "$folder" )"
    name="$(basename "$folder" )"
    cd ${directory}
    zip -9 -r --exclude=*.svn* --exclude=*DS_Store ${directory}/${name}.zip ./"$name"
  8. Save the service with whatever name you want. I chose 'Compress without Hidden Files'

 Running the Service

  • In the Finder, go to the folder that you want to compress
  • Right-click the folder, go to 'Services' in the menu and choose 'Compress without Hidden Files' (or whatever you named your script)
  • A zip file will show up in the directory with the same root name as your folder

Configuring the Script

If you want to add or remove exclusions from the zip file, change the next to last line of the shell script.

  • Add a folder exclusion:
  • Add a file exclusion:

If you find any bugs or have any great modifications for the script, let me know.

About the Author

Dave Rogers

Dave is the founder of Sky Blue Sofa Web Design. He enjoys working out, spending time with his wife and dogs and programming. He grew up and currently resides in the Illinois Quad Cities. You can find his personal blog at strength/

View Profile »


You must be logged in to leave a reply. Login »