Watching for high CPU utilization

Is there a way for Keyboard Maestro to trigger if an application starts chewing up the CPU? I have a couple of ill-behaved programs that need to be force quit from time to time and restarted because they start using up large amounts of the CPU. The problem has been reported to the developer, but until it’s fixed, I’d like KM to do it for me, if possible.

Hey There,

If you want a turnkey solution then you'll probably want something like App Tamer.

http://www.stclairsoft.com/AppTamer/index.html

But you can certainly roll-your-own with Keyboard Maestro.

You'll have to run something like ps from in an Execute Shell Script action.

ps -u <your-user-name> -c -o %cpu,pid,command | egrep "[0-9]{2,}\."

An example:

ps -u George_Orwell -c -o %cpu,pid,command | egrep "[0-9]{2,}\."

Output looks something like:

 12.1   548 BBEdit

In this case I'm only looking for 2 non-decimal digits, and you would certainly want to make that more specific.

I'm also looking only at a specific user's applications, but that of course can be made more general.

This will fail silently if there is no output from the command, but it will open a window with the result if/when there is output:

You could run something like thes with a timed-trigger and refine it to work like you want.

-Chris

1 Like