I guess it’s not surprising everybody wants to stop the screensaver from engaging to keep their scripts running. I too gave scripting the screensaver a shot for the same reason, but I closed my prefences panes with a GUI click command and just like jfowler I found that the screen saver values did not change.
Adam, according to what you just said,
why doesn’t that allow the GUI method work when we close the pane?
StefanK, thanks for the tip. Can you restart “ScreenSaverEngine” again later, or will you have to do a restart on the computer?
For anybody interested, my attempt at shutting down the screensaver was a general one of trying to set the time which presented a problem because the time scale is not linear. So I tried to do it by sliding the slider forward and reading the name of static text 11 to tell where I was. It didn’t work any better than jfowler’s, but it was kinda cool to actually see the slider slide. Also, I just discovered the script has at least one bug - - when the slider is originally set to never, there was an error. I just discovered it and didn’t bother to see what the problem is. Probably trying to read the word ‘never’ as a number maybe. I’ll look at it later.
adjustScreenSaverTime(20)
to adjustScreenSaverTime(myTime)
-- Independent
(* myTime is in minutes *)
set validTimes to {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 55, 60, 70, 81, 90, 100, 109, 120}
set n to count of validTimes
set staticText to "0"
set highTime to item 1 of validTimes
if myTime < highTime then set staticText to (highTime as string) & " minutes"
repeat with i from 2 to n
set lowTime to item (i - 1) of validTimes
set highTime to item i of validTimes
if myTime > lowTime and myTime ≤ highTime then
set staticText to ""
set hours to highTime div 60
if hours = 1 then set staticText to "1 hour"
if hours = 2 then set staticText to "2 hours"
set minutes to highTime mod 60
if hours = 0 then set staticText to (minutes as string) & " minutes"
if hours = 1 then set staticText to staticText & " " & (minutes as string) & " minutes"
end if -- myTime > lowTime and myTime ≤ highTime
end repeat -- with i
if myTime > highTime then set staticText to "Never"
set mystaticText to staticText
tell application "Finder"
activate
tell application "System Events"
tell process "Finder"
click menu item 5 of menu 1 of menu bar item 1 of menu bar 1
end tell -- process "Finder"
end tell -- application "System Events"
end tell -- "Finder
delay 1
tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
click button 3 of scroll area 1 of window 1
delay 1
tell group 1 of tab group 1 of window 1
set sliderValue to minimum value of slider 1
set minSValue to minimum value of slider 1
set maxSValue to maximum value of slider 1
set staticText to name of static text 11
if mystaticText = "Never" then
set value of slider 1 to maxSValue
else
repeat until staticText = mystaticText or sliderValue ≥ maxSValue
set value of slider 1 to sliderValue
set staticText to name of static text 11
set sliderValue to sliderValue + 3
end repeat
end if -- mystaticText = "Never"
end tell -- group 1 of tab group 1 of window 1
delay 1
click button 1 of window 1
end tell -- process "System Preferences"
end tell -- application "System Events"
end tell -- "System Preferences
tell application "Script Editor"
activate
end tell -- "Script Editor"
end adjustScreenSaverTime