Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


10.2 | 7 comments | Create New Account
Click here to return to the '10.2' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.2
Authored by: mzs on Sep 05, '06 11:53:13AM
This should work in 10.2, it used to but I have made changes to the script since then:

#!/bin/sh

# Display idle time

foo='
/^[ |]*"HIDIdleTime" = / {
        # 10.2 and earlier uses CFData, later uses CFNumber
        if (substr($NF, 1, 1) == "<") {
                fmt="scale = 9; obase = 10; ibase = 16; %s / 3B9ACA00"
                v=toupper(substr($NF, 2, 16))
        } else {
                fmt="scale = 9; %s / 1000000000"
                v=$NF
        }

        line=sprintf(fmt, v)
        cmd="/bin/sh -c '\''echo \"" line "\" | bc'\''"
        cmd | getline line
        close(cmd)

        fmt="+%H:%M:%S"
        i=index(line, ".")
        if (i)
                fmt=fmt substr(line, i, 10)

        fmt=" '\''" fmt ", " line "s'\''"
        cmd="date -nur " line fmt
        cmd | getline line
        close(cmd)

        print line
        exit 0
}
'

ioreg -c IOHIDSystem | awk "$foo"
This gives nicer output like this:

% idletime 
00:52:04.493391248, 3124.493391248s
(I was ssh-ed in.)

[ Reply to This | # ]