Last active
August 29, 2015 14:27
-
-
Save cuibonobo/875f94cdcd1c5ba91a63 to your computer and use it in GitHub Desktop.
How to detect that a person has been idle on Mac OS X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Output is given in seconds. Taken from http://stackoverflow.com/a/8659356 and *originally* from | |
| # http://hints.macworld.com/article.php?story=20040330161158532 (posted in 2004!!) | |
| echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my travels I have found 2 other ways to parse the output of
ioreg -c IOHIDSystem. The first usesawkto parse the output:The second uses a combination of
grepandawk:While they are easier to read than the original, the
sedstill beats the first one on speed and the second one on the number of pipes (and arguably on speed also, but the margin is much closer).