检查显示是否处于睡眠或接收睡眠通知 [英] Check if display is at sleep or receive sleep notifications

查看:112
本文介绍了检查显示是否处于睡眠或接收睡眠通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序实用程序,当没有用户时变得无用。因此,为了节省资源,我想知道什么时候/显示是否处于睡眠状态。

I have an application utility which becomes useless when there's no user. So, in order to save resources, I'd like it to know when/whether display is at sleep.

有一个专用文章关于苹果的唤醒/睡眠通知,但它只处理计算机睡眠而不显示睡眠。

There's a dedicated article about wake/sleep notifications by apple, but it deals only with computer sleep and not display sleep.

当显示器处于睡眠状态时,应用程序是否有休眠的方法?

Is there a way for application to 'hibernate' when display is at sleep?

谢谢


Thank you

推荐答案

因为我找不到任何由显示器发出的呼叫进入睡眠状态(也许屏幕保护程序是这样吗?在系统下降到睡眠之前踢),我建议手动检测空闲时间,然后将其与显示器睡眠设置进行比较。
本文介绍了如何从IOKit获取空闲时间,你应该能够轻松获得当前的睡眠设置,例如pmset -g | grep sleep。

Since I couldn´t find any call issued by the display falling to sleep (maybe the screensaver does that? It´s very likely to kick in before the system falls to sleep), I´d suggest detecting the idle time manually and then comparing it to the display sleep settings. This article covers how to get the idle time from IOKit and you should be able to easily get the current sleep settings, e.g. with "pmset -g | grep sleep".

发布了上面的两分钟后,我发现了一个开源命令行工具,可能会帮助你到那里: SleepWatcher 似乎能够满足您的要求。

Two minutes after posting the above, I discovered an open source command line tool that will probably help you a lot getting there: SleepWatcher seems to be able to do just what you asked for.

这篇关于检查显示是否处于睡眠或接收睡眠通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆