Today I got a little bit annoyed at the fact that PersonalBrain constantly uses some 5-10% CPU time even when it's sitting in the background getting no input from me, so I decided to do something about it. This solution may only appeal to the technical inclined, but it does work for me (and makes me happy!) so I thought I'd share:
PB stop toggler
Fortunately, the underlying system on the Mac has a nifty feature that you can use to temporarily stop an application: our old Unix friend, kill -STOP <pid> and its counterpart, kill -CONT <pid>. It works like a charm, except of course you need to somehow figure out the pid, and type it in a terminal, which is not so practical, right?..
But hey! here comes Applescript (and bash, and perl, and...). So, I wrote a shell script that finds the pid of a PersonalBrain.app instance (caveat: it only works when there's only one running!). After that, it also kills it with the right signal to toggle its state (from stopped, which shows as T in ps, to running -- or the other way around). It's a one line file (OK, two lines including the header). Looks gory, but should work fine:
% cat /Users/Shared/toggleBrain.sh
ps ax | grep PersonalBrain.app | grep -v grep | perl -lne '($a,$pid,$c,$_) = split / +/; /T/ && print "-CONT $pid"; /T/ || print "-STOP $pid"' | xargs kill
This isn't a good place to explain in detail what happens there. Anyway, most of the goreness comes from parsing the output from "ps"; if you want to debug it for some reason, just replace "kill" with "echo" and it won't do anything other than string matches and printing arguments that should go to the kill command.
In Applescript, all that's needed is one line script with a call to:
do shell script "/Users/Shared/toggleBrain.sh"
which I saved to my user scripts directory. Applescript editor has a "General" config option that lets you "Show Script menu in menu bar" - try it and you should figure out the rest for yourself if you care. The little saved script should appear at the bottom of the menu and should toggle PB between running (and wasting a tenth of your CPU power) and stopped (which just shows a circling ball cursor over the brain window).
I know, it would have been nicer if it were automatically detecting when PB gets focus, but I don't know how to do that. Of course, even nicer would have been for the PB developers to get a grip on their CPU eating Java code!
If you followed me so far, thanks, and have fun.