I specialise in creative use of digital media, copywriting, and bright ideas.

I'm passionate about all things digital, electronic music, graphic design/typography, public information campaigns, theatre, and many weird and wonderful things in between.


Bash script to backup OS X apps

As a happy OS X user with a healthy distrust for Apple and the App Store, I wanted to back up my apps to a DVD-R. After having to reinstall OS X one day, I reached for my backed-up apps disc, only to find a significant problem: it takes ages to copy them back. So long, in fact, that I ended up downloading them all from the App Store again, which rather defeated the point of backing them up.

You might not realise this - in fact, I think Apple don't want you to realise - but each app isn't a file; it's actually a folder containing 100s of files. That's why you can move most apps around on the system without affecting how they work. As a reformed Windows user, this took me a while to get my head around.

So, in order to back them up to removable media, you're going to have to compress the .app 'files' first. This little bit of code will compress each .app folder to an individual tar.gz file.

  1. Make copies of all the apps you want to back up in a folder, for example one on your Desktop called 'apps'.
  2. Open a terminal and type the following command (all one line):
    find *.app -maxdepth 0 -type d -print0 | while read -d $'\0' f; do echo "${f}"; tar -czf "${f}.tgz" "${f}"; done
  3. Wait (up to ages depending on how many apps you're compressing)
  4. Delete the original .app file copies, and burn your .tgz files to a disc!

Then, when you need to recover an app, just extract it from the .tgz file using something like The Unarchiver.

Hardcore version: this one also deletes the .app file/folders as it goes along.
Use at your own risk!:

find *.app -maxdepth 0 -type d -print0 | while read -d $'\0' f; do echo "${f}"; tar -czf "${f}.tgz" "${f}"; rm -rf "${f}"; done

Thanks to Andy for help in getting this working.