如何关闭 Mac 屏幕保护程序?
我正在编写一个使用 Apple 的信息亭模式的应用程序。我想禁用屏幕保护程序,但“ScreenSaverDefaults”类将其自身报告为仅 32 位。我可以将构建更改为仅 32 位,但我也希望能够支持 64 位架构。
我还应该使用其他框架来禁用屏幕保护程序吗?
I'm writing an application that uses Apple's kiosk mode. I would like to disable the screen saver, but the "ScreenSaverDefaults" class reports itself as being 32-bit only. I can change the build to be 32-bit only, but I would like to be able to support 64-bit architectures as well.
Are there any other Frameworks that I should use to disable the screen saver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您需要保存当前设置,以便可以将其恢复到关闭之前的状态:
现在您拥有了屏幕保护程序空闲时间的原始值。伟大的!不要失去那个。现在,您必须设置新值:
还有中提琴!您刚刚禁用了屏幕保护程序。要重新启用它,只需再次使用第二个代码块,但传入 OriginalValue 作为最后一个数组对象而不是
@"0"
,如下所示:享受!
Billy
P.S.:最后一件事,您可能会想保存 NSTask 对象以重新使用它们,但不要这么做。它们只能运行一次,因此每次您想要执行此操作时都必须创建新的。
First, you need to save the current setting, so you can put it back the way it was before you turned it off:
So now you have the original value for the screensaver's idleTime. Great! Don't lose that. Now, you have to set the new value:
And viola! You've just disabled the screensaver. To re-enable it, just use the second block of code again, but pass in originalValue as the last array object rather than
@"0"
, like so:Enjoy!
Billy
P.S.: One last thing, you may be tempted to save the NSTask objects to re-use them, but don't. They can only be run once, so you'll have to create new ones every time you want to do this.
对于任何正在寻找如何执行此操作(就像我一直在做的那样)并且不想浪费时间编辑首选项文件的人来说,Apple 有一种适当的方法可以在应用程序运行时阻止屏幕保护程序启动。
技术问答 QA1160:防止睡眠
希望这会有所帮助。
For anyone searching for how to do this (like I have been doing) and don't want to mess around with editing the preference files, Apple has a proper method to stop the screen saver from starting up while your application is running.
Technical Q&A QA1160: Preventing sleep
Hope this helps.
我最终做的是直接读取 com.apple.screensaver 首选项文件并修改idleTime 和askForPassword 值以使它们为零。一个简单的
CFPreferencesSynchronize
就一切顺利!What I ended up doing was directly reading the
com.apple.screensaver
preference file and modifying theidleTime
andaskForPassword
values so that the are zero. A simpleCFPreferencesSynchronize
and all was well!