Check if display is at sleep or receive sleep notifications

前端 未结 3 1586
时光说笑
时光说笑 2021-02-06 19:16

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\'

3条回答
  •  情书的邮戳
    2021-02-06 19:55

    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".

    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.

提交回复
热议问题