view collector/idle_osx.py @ 10:6b6b1ea0e00d default tip

ok for no window to be focused (untested)
author drewp@bigasterisk.com
date Mon, 13 Mar 2023 19:16:58 -0700
parents 5ad799e534a5
children
line wrap: on
line source

import subprocess


def get_idle_seconds():
    for line in subprocess.check_output(['ioreg', '-c', 'IOHIDSystem'],
                                        encoding='ascii').splitlines():
        if 'HIDIdleTime' in line:
            ns = float(line.split(' = ')[1])
            return (ns / 1000000000)
    raise ValueError("idle time not found")