I’ve often wondered how to know this. Here are two ways (in a script that gives a delay so you’ll see if you don’t touch anything after you click “Execute”.
delay 8
-- From http://www.macosxhints.com/article.php?story=20040330161158532
set iT_1 to (do shell script "echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))") as real
-- From Mark Hunte
set iT_2 to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as real
Who cares? Suppose you want to do some maintenance routine if the machine has been idle for a while. An on idle stay-open application will do the maintenance on every return, but this will wait:
property howLong : 600 -- ten minutes
on idle
set idleTime to (do shell script "ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'") as number
if idleTime > howLong then
-- Post a notice and do your maintenance
end if
return howLong
end idle