scripting CPU usage of a process

I’d like to get the value of the CPU usage of a process inside an apple script. Is that scriptable? If not, I believe there is a unix command to do that. Could somebody tell me what that is and how to pass its output to apple script?

Hi,

try this


getProcessPercentCPU("Finder")

on getProcessPercentCPU(someProcess)
	do shell script "/bin/ps -xco %cpu,command  | /usr/bin/awk '/" & someProcess & "$/ {print $1}'"
end getProcessPercentCPU

Thanks! This seems to work ok most of the time but for some reason it doesn’t work on some processes. For example, when I run it on Firefox I always get an empty result. Do you know why this happens?

the process of FireFox is called firefox-bin

you get a list of all running processes with

do shell script "/bin/ps -xco %cpu,command"