You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下ioreg获取用户空闲时间失效,求新Shell实现方案

macOS 获取用户空闲时间的当前可行Shell方案

方案一:更新ioreg命令参数

旧版ioreg命令失效是因为系统对IOHIDSystem的属性结构做了调整,添加-a(显示所有属性)和-r(递归遍历)参数后可正常获取:

ioreg -a -r -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'

该命令会输出用户已空闲的秒数,目前在macOS Ventura、Sonoma等新版本中可用。

方案二:使用AppleScript接口(推荐)

通过System Events提供的官方接口获取,无需解析底层设备信息,兼容性和稳定性更强:

osascript -e 'tell application "System Events" to return idle time'

执行后直接返回空闲秒数,是更可靠的长期方案。

内容的提问来源于stack exchange,提问作者Robert de Forest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 00:22:04