System Idle Time

Hi! Does anyone have a plugin-free solution to get OS X (Cocoa) system idle time?

This shell command returns idle time in seconds. You could use a Shell class and extract it from results.

/usr/sbin/ioreg -c IOHIDSystem | /usr/bin/perl -ane 'if (/Idle/) {$idle=int((pop @F)/1000000000); print $idle,"\ "; last}'

I’d have a peek in MacOSLib as well

[code]Function SecondsSinceLastInput() As Double
Declare Function CGEventSourceSecondsSinceLastEventType Lib “ApplicationServices” ( stateID As UInt32, eventType As UInt32 ) As Double
Const kCGEventSourceStateCombinedSessionState = 0
Const kCGAnyInputEventType = -1

Return CGEventSourceSecondsSinceLastEventType( kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType )
End Function[/code]

Thanks everyone! I think I’ll go with Joe’s solution, just what I needed.