API for System Preferences to disable the screen saver

Discussion in 'Mac Programming' started by fletch22, May 9, 2007.

  1. fletch22 macrumors newbie

    Joined:
    May 9, 2007
    #1
    Hi-

    I am wondering if there is a c/c++ API for the system preferences that I can use to disable the screen saver. I'd like to do this:

    * read the settings that the user has (how long until screen saver activates, etc)
    * disable it
    * when my app exits, re-enable the settings saved previous.

    Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The basic answer is no.

    You might be able to get access via the the CFPreferences API if you know the correct AppId & Domain to pretend to be that preference pane, but there is no guarantee that updating the preference behind the back of the preference pane and screen saver system would work: you may need to inform it via some private API that this has changed.

    Edit to add: a better way would be to not monkey around with the users settings (what if your app crashes). Instead stop the screen saver activating at all. A possible way of doing that is discussed here.
     
  3. garethlewis2 macrumors 6502

    Joined:
    Dec 6, 2006
    #3
    What you are asking to is take control of the machine and cirumvent any user authority. There is absolutely no way that Apple would ever create an API that allowed that, while running Aqua. The only way to do something like this, is to create a windowless app that runs full screen, something like a game or FrontRow.
     
  4. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #4
    I'd be surprised if some apps don't already do this, such as DVD player and Quicktime player.

    There is one way I can think of to do this indirectly that would almost certainly work, but may or may not be suitable for the OP. I am curious why he needs to do this though.
     
  5. Nutter macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #5
    Why would DVD Player and QuickTime Player do this? They probably just update the system activity timer.

    Actually disabling the screen saver to stop it from appearing is a bit of a hack! Imagine if your app crashes or is force quit - the user will never see their dear screen saver again.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    They almost certainly use the technique I posted a link to above (updating the activity timer).
     
  7. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #7
    Sorry, I was referring to disabling the screen saver, rather than that specific method of disabling it. As you say, there are obvious disadvantages in that method.

    Updating the system activity is 'the' way to do it, and is what we use in our Mac apps.

    Incidentally, what the OP wants could be done via GUI scripting, though it would be rather messy.
     

Share This Page