有没有办法监控 Mac 何时即将进入睡眠状态?

发布于 2024-12-08 11:13:13 字数 67 浏览 3 评论 0原文

是否有一种编程方式可以监控 Mac 何时进入睡眠状态?我想监视用户何时故意告诉系统进入睡眠状态以及系统何时准备自然睡眠。

Is there a programmatic way to monitor when a Mac is about the to go sleep? I would like to monitor when the user deliberately tells the system to go to sleep and when the system is preparing to sleep naturally.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹淡然 2024-12-15 11:13:13

您可以像这样注册以下通知:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveSleepNotification:) name:NSWorkspaceScreensDidSleepNotification object:NULL];

您可以像这样注册唤醒通知:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveWakeNotification:) name:NSWorkspaceDidWakeNotification object:NULL];

You can register for the following notification like this:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveSleepNotification:) name:NSWorkspaceScreensDidSleepNotification object:NULL];

You can register for a wake notification like this:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(receiveWakeNotification:) name:NSWorkspaceDidWakeNotification object:NULL];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文