In terminal we can use
top -l 2 -F -R | awk '/CPU usage/ && NR>5 {printf "%d", $7+0}'
to get the value of cpu usage how can i get the value as an integer in apple script?
i tried this
set usedSpace to (do shell script "top -l 2 -F -R | awk '/CPU usage/ && NR>5 {printf "%d", $7+0}'") as integer
and gor the error
Expected “,” but found unknown token
then tried like this
set usedSpace to (do shell script "top -l 2 -F -R | awk '/CPU usage/ && NR>5 '; printf $5}") as integer
and got an error like this
error “Can’t make \”CPU usage: 6.40% user, 5.41% sys, 88.17% idle }\”
into type integer.” number -1700 from “CPU usage: 6.40% user, 5.41%
sys, 88.17% idle }” to integer
can anybody help me solve this?
Thanks in advance
Try:
or