Hazel rule for deleting OmniFocus backups (without deleting them all)

David Sparks (@macsparky) and Katie Floyd (@katiefloyd) over at Mac Power Users covered a lot of great Hazel tips for those looking to automate the more mundane (yet important) aspects of electronic file management in episode 79 of the Mac Power Users podcast. Check it out. Subscribe.

The problem

As the owner of a MacBook Air, I was looking to keep a lid on the size of OmniFocus’ backups directory. As an example of how this can get out-of-hand, on my iMac this directory had nearly 900 files (dating back more than 3 years), and had swelled to over 70 GB. This was choking my Time Machine drive to death, and clearly wouldn’t make the tiny, SSD on my MacBook Air very happy.

Noodlesoft's Hazel iconThe solution

David’s suggestion was to make a Hazel rule that would delete any files older than a certain age; a couple of weeks, for example. That’s a great idea that I implemented immediately.

The fly in the ointment

Then I had a thought: what if I go on vacation for a month (I know: never happen — work with me, here), or work exclusively from one workstation for 3 weeks? Hazel will, as instructed, delete all of the backups on me. Not so cool.

As it happens, I had asked Noodlesoft about making a rule that would allow deleting files older than a certain date but retaining a certain minimum number of files, and they told me it wasn’t possible. That was before Hazel 3.0 came out, though.

The answer

Now it can be done. Add a rule (choosing “Other…” from the pop-up menu and searching for “number”). Set the “Number of items” to whatever you’re comfortable with. I chose 5.

Here’s the screenshot:

Hazel rule screenshot

And here’s the finished rule:

Hazel rule 668x320

Now any backups older than 7 days are tossed, but I’ll always have at least 5 files retained. Sweet.