7

Is there a way to disable the screen saver and the display sleep with cocoa?

lbrndnr
  • 3,361
  • 2
  • 24
  • 34
  • I've just solved it. Call UpdateSystemActivity(OverallAct) every 30 seconds – lbrndnr Feb 26 '11 at 13:35
  • 2
    When 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 Answers2

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.

herzi
  • 774
  • 6
  • 18
Giles
  • 1,428
  • 11
  • 21
  • 1
    Actually 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
  • this prevents display sleep, but not the screensaver – Hogdotmac Jan 04 '22 at 21:26
4

i've just solved it and forgot to post it as an answer. Calling UpdateSystemActivity(OverallAct) every 30 seconds works.

Joe Shaw
  • 22,066
  • 16
  • 70
  • 92
lbrndnr
  • 3,361
  • 2
  • 24
  • 34