Is there a way to disable the screen saver and the display sleep with cocoa?
Asked
Active
Viewed 3,939 times
7
-
I've just solved it. Call UpdateSystemActivity(OverallAct) every 30 seconds – lbrndnr Feb 26 '11 at 13:35
-
2When I first read your comment I thought that seemed like a bit of a hack, but apparently it is [sanctioned by Apple](http://developer.apple.com/library/mac/#qa/qa1160). At least as of 2004. – SSteve Aug 10 '11 at 19:22
2 Answers
8
The use of UpdateSystemActivity(OverallAct) has been deprecated in OSX 10.8.
The recommended approach is now to block it with the following call:
IOPMAssertionCreateWithName(kIOPMAssertionTypePreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
See this Apple Q&A for further details.
-
1Actually on 10.8 this code will not only prevent the display from going to sleep but also stop the screensaver from activating. I wonder why this behavior got changed, since this call always prevented the screen from sleeping, yet it did not stop the screensaver in the past (not sure if this was changed in 10.8, 10.7 or even 10.6). – Mecki Oct 28 '13 at 19:35
-