screensaver deactivation help

I’m trying to read-in the user’s screensaver time and then deactivate the screensaver. Their setting will be restored later. So far, I’ve managed to manipulate the System Prefs for this, but the change doesn’t stick. Any ideas?


	tell application "System Preferences"
		activate
		set current pane to pane "com.apple.preference.desktopscreeneffect"
	end tell
	tell application "System Events"
		tell application process "System Preferences"
			tell window 1
				if value of radio button "Desktop" of tab group 1 is 1 then click radio button "Screen Saver" of tab group 1
				tell tab group 1
					tell group 1
						get value of slider 1
						set screensaver to result -- get user's value for screensaver
						set value of slider 1 to 361.0 -- deactivate screensaver
					end tell
				end tell
			end tell
		end tell
	end tell
	delay 1
	tell application "System Preferences" to quit

Model: PBG4 15" 1.67/2GB/120GB
AppleScript: 2.1.1 – or whatever’s current
Browser: Safari
Operating System: Mac OS X (10.4)

The easiest way to get the user’s displaysleep time is with a shell script:

do shell script "pmset -g | grep displaysleep" --> " displaysleep xx"

That doesn’t have to be parsed for the number because to reset, you’d use it as is.

To set that to never you would use the script below, but obviously that presents the problem of not knowing the password, so your app would have to ask for it. If the user might not have administrator privileges, then this won’t work at all. Finding out does not require a password - setting values for pmset does.

do shell script "pmset displaysleep 0" user name "shortnameHere" password "aPassWd" with administrator privileges

Sadly, this won’t work for my uses…this script will be run on a variety of machines and I don’t really want to recompile for every Mac…

I thought not. Reading the value will work for you this way, however, but GUI scripting is not the only way to prevent sleep. I don’t know what you’re doing, but if hitting the space bar won’t disturb it, for example, then an idle handler with a system events keystroke spacebar done faster than the sleep setting will do it too. If that’s no good, there are ways of moving the mouse one pixel and back again every so often.

how would you script mouse movement? Another part of the script is replicating keystrokes, but the screensaver still kicks-in.