The disadvantage of coding a tool what reads the current CPU usage once and quit is, that it has to wait some time before getting a acceptable value. Because the tool by itself rise the CPU and System usage on start (allocate resources, ...).
I have used
iostat to get the CPU usage. From my AppleScript application I run the command
Code:
/usr/sbin/iostat -Iw1 -n0
and redirect the output into a file on a ramdisk. From this file I read regulary the last line and get the CPU usage from it. The RAM disk will be created on start of the application and destroyed on quit.
I hope this helps you. The best would be, you redirect the output into a pipe. This should possible in Cocoa/ObjectC, because it's also possible in JavaScript.
ByE...