Disable Screen saver - driving me nuts - yes I searched for this...

Ok, after hours of searching and trial and error, I’m plumb out if ideas. I need a script that will automatically disable the screen saver or set the time to start to ‘never’. This would seem a simple task but something is very wonky… I’ve tried a bunch of different methods:
¢do shell script "usr/bin/defaults -currentHost write com.apple.screensaver idleTime 0
didn’t work - meaning the setting didn’t show up after entering this command. On that note, there’s a similar command with remote desktop (or maybe i put it there and forgot), but it doesn’t take effect until you restart the computer. Even that isn’t working.

¢tell slider 1 of group 1 of tab group 1 of window “Desktop & Screen Saver”
set value to n
I just set n to 1000 and it will go to never, but it won’t keep the setting either.

¢last ditch, I put the delay’s in there just in case:
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke tab
delay 0.5
keystroke (ascii character (116) --page up sends the slider to the end



also won't keep the setting.

what
the
crap

I know the damn thing works if I set it manually.  I've tried all of the above on two machines, one with a fresh install of 10.4.6 just to be sure I hadn't screwed something up and nothing.  Assistive devices is enabled and the rest of the script that does other uninteresting things works fine.

*shakes hands in the air

any thoughts?

Welcome to the forum! :slight_smile:

Does this work for you?

tell application "System Preferences"
	activate
	set current pane to pane id "com.apple.preference.desktopscreeneffect"
	reveal anchor "ScreenSaverPref" of current pane
end tell

tell application "System Events"
	tell process "System Preferences"
		set value of slider 1 of group 1 of tab group 1 of window 1 to 361 -- "Never"
	end tell
end tell

Thanks for the welcome!

All of the previously mentioned scripts (including the one you just sent me) do something, but it won’t keep the setting, meaning, if I quit System Prefs, and re-open the screen saver panel, the setting will be whatever it was previously. Its almost like clicking and dragging the slider to the end and never letting off the mouse button, though obviously not literally what’s happeneing…

oi

Nice catch Jacques. :cool:

Is the functionality of a hot corner set to disable the screen saver not what you want?

Not really… see, I’m running some automation on about 13 machines and I reimage them about once a week and it would save me a bunch of time if certain settings would just, set themselves. Energy saver will save settings across images, but the screen saver won’t unfortunately. So far I’ve got my script to do everything I need it to do except this.

Interesting… that seems to work, but only if the system preferences aren’t open… but that’s not really a problem. Thanks, that seems to work!

System Preferences saves its setting when you close it. That’s why it doesn’t work with SP open.

Thanks everyone for the help, here’s what I came up with and it works. I need to add some more delays for slower machines but it basically works fine. After looking at it again, I realize there are some spots that could probably be optimized, like setting the sound with a shell script instead of using the UI script and whatnot.

Basically the script copies the machine name out of a text file on a fixed partitions on each machine (isn’t going to get reimaged) into the system prefs after I reimage all of the machines with the same image so that they don’t all end up with the same name. Here it is:

delay 15
--supress name in use error
tell application "UserNotificationCenter"
	quit
end tell
--get share name
tell application "TextEdit"
	
	activate
	open file "Volumes:Media:name.rtf"
	tell application "System Events" to keystroke "ac" using command down
	quit
end tell
--disable screen saver
tell application "System Events"
	tell process "System Preferences"
		do shell script "/usr/bin/defaults -currentHost write com.apple.screensaver idleTime -int 0"
	end tell
end tell
--everything else
tell application "System Preferences"
	activate
	tell application "System Events"
		tell process "System Preferences"
			delay 0.5
			--Set Font smoothing to Standard-best for crt
			click menu item "Appearance" of menu "View" of menu bar 1
			delay 2
			click pop up button 4 of window "Appearance"
			click menu item 2 of menu 1 of pop up button 4 of window "Appearance"
			delay 1
			--mute sound
			click menu item "Sound" of menu "View" of menu bar 1
			delay 2
			click radio button "Sound Effects" of tab group 1 of window "Sound"
			tell slider 1 of group 1 of window "Sound"
				set value to 0
			end tell
			--remove script from startup items
			click menu item "Accounts" of menu "View" of menu bar 1
			delay 2
			click radio button "Login Items" of tab group 1 of window "Accounts"
			tell application "System Events"
				delete (first login item whose name is "autoset")
			end tell
			--set share name
			click menu item "Sharing" of menu "View" of menu bar 1
			delay 2
			keystroke tab
			delay 2
			keystroke "v" using command down
			keystroke "q" using command down
			
		end tell
	end tell
end tell

Feel free to pick at it if you think of something simpler that I’m not doing here.

You can mute sound with this instruction (if the Pref pane isn’t open, see below):

set volume with output muted

restore it with

set volume without output muted

And neither of them need a tell block. AppleScript will handle it.

In this:


tell application "System Events"
   tell process "System Preferences"
       do shell script "/usr/bin/defaults -currentHost write com.apple.screensaver idleTime -int 0"
   end tell
end tell

You don’t need to ‘tell’ anything. You are going straight for the jugular. The do shell… will do it, IF the System Preferences pane is NOT open - closing the window refreshes the setting to whatever is there instead of this so do it after the Pref Pane stuff.

I don’t think you need any GUI scripting for this (it works by itself):


tell application "System Events" to delete (first login item whose name is "autoset")

And because you are already in a ‘tell application “System Events”’ block, you don’t need that either; just do it inside the tell app “System Events” after you end the tell process… block. The shell script can go outside of any tell block, as can the mute volume. Telling, when not needed, is just an unnecessary “I can’t do this so I’ll pass it up the chain” decision.