Monday 3 November 2014

Jeeves is my new Belvedere

I've gotten kind of excited about a very simple program I've written recently, called Jeeves. It's a replacement for a program I got from Lifehacker that was called Belvedere (so I kept up the butler naming scheme). Basically, Belvedere is able to monitor folders on your hard drive, watching for certain conditions (such as files last modified before a certain date) and take actions in response, such as moving them to the recycle bin. I find it very useful for keeping my Downloads folder clean by setting it to watch for files older than a fortnight.

What bothered me was that Belvedere couldn't look for empty folders and remove those. I've tried various approaches to the problem, including writing a simple C# program to find and delete empty folders. That path started leading me to write a replacement for Belvedere, with configurable Trigger items and Actions to take in response. This turned out to be a very tricky and complicated way to operate, involving passing values back and forth in a generalised and highly flexible way, figuring out how to save and load rules and generally getting very messy. I abandoned the project for a long while.

Recently, I hit on the idea that maybe Python would be a better fit for the functionality, but I still couldn't figure out how to save and load the rules to be run by the generalised rule engine.

Then it hit me. Why do I need a generalised rule engine at all? If my goal is to run arbitrary actions in response to arbitrary conditions, then I should just write scripts to do what I want directly. Suddenly Jeeves, instead of being a complex, extensible file and folder monitoring rules engine, became a lean set of a few helper methods. Now my scripts are machine-specific simple Python programs that consist of statements like:

delete_folders(empty_folders("C:/temp"))

That's a Jeeves rule that deletes any empty folders under the temp folder. It's such an easy kind of rule for me to write that I hardly need to think about it. It also neatly sidesteps all of the problems I was having with the C# version. I schedule this file with the Windows Task Scheduler, and it works brilliantly. Belvedere, unfortunately, you're fired. I have Jeeves now.

Mokalus of Borg

PS - I recognise that this system isn't good for non-programmers.
PPS - Since it's just for me, that is not an issue.

No comments: