I was looking for some way to tell if a remote machine was idle from the commandline and I stumbled across this snippet on Mac OS X Hints.
ioreg -c IOHIDSystem | awk ‘/HIDIdleTime/ {print $NF/1000000000; exit}’
returns a time in seconds and fractions thereof, ie 4.00711