AppleScript to disable screen saver

  • Posted: 24 November 2008 11:23 AM

    I am new to AppleScript and would like to write a script that will disable my Energy and screensaver so that I can watch movies from the internet on my Mac without the screen saver coming on and without the display or computer going to sleep.

    To start with I would like to disable the screensaver.  I have no clue as to how to do this but I came across this code on the net:

    set prefsFolder to (path to “pref”)‘s POSIX path & “ByHost/”
    tell application “System Events”
    set prefsFile to property list file ((folder prefsFolder’s first file where name starts with “com.apple.screensaver.”)‘s POSIX path)
    tell prefsFile
      set value of property list item “moduleName” to “Computer Name”
      set value of property list item “idleTIme” to 10
      set value of property list item “modulePath” to “/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver”
    end tell
    if exists process “System Preferences” then quit application “System Preferences”
    end tell

    I removed two of the set value properties list time lines so the code reads:

    set prefsFolder to (path to “pref”)‘s POSIX path & “ByHost/”
    tell application “System Events”
    set prefsFile to property list file ((folder prefsFolder’s first file where name starts with “com.apple.screensaver.”)‘s POSIX path)
    tell prefsFile
      set value of property list item “idleTIme” to 10
    end tell
    if exists process “System Preferences” then quit application “System Preferences”
    end tell

    When I try to run the code I get:

    AppleScript Error
    System Events got an error: Can?t set property list item “idleTIme” of property list file “Macintosh:Users:stevewetzel:Library:Preferences:ByHost:com.apple.screensaver..Mac.001b6393d9e7.plist” to 10.

    What am I doing wrong?  More importantly, how and where would I ever find that documentation to assist me in learning that I need to use prefsFolder (whatever that is), to do this?

    Can anyone offer some assistance??

    Signature

    Wow this is so much better then my old Mac Plus!
    Steve