Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to write an applescript that will disable the screen saver through sending a keystroke. Something like sending a "shift key" pressed every 30 seconds.

I don't want to have the applescript actually disable the screen saver through system preferences.

share|improve this question
1  
lightheadsw.com/caffeine perhaps ? –  Kassym Dorsel Nov 7 '11 at 5:19
add comment

3 Answers

Check out the dictionary for the System Events app that's included with Applescript. You can access it from the AppleScript Editor:

File > Open Dictionary... > System Events.app

There's a class called "screen saver preferences object" in there that should do what you need without having to script the GUI.

EDIT: Try setting the property "delay interval" of the object to 0 to disable the screensaver.

share|improve this answer
1  
So basically: tell app "System Events" to tell screen saver preferences to set delay interval to 0. Display sleep might need to be disabled separately. –  Lauri Ranta Nov 7 '11 at 11:18
add comment

You could also use an on idle() handler, like this:

on idle
   -- Add your code here to keep the computer awake.
   return 1800 -- The number of seconds the script should delay before being idle again
end idle

but the screen saver prefs obj is a better tool. It does exactly what you want.

share|improve this answer
add comment

You have defined HOW you want to solve the problem. I don't think that is the right approach. I think you should consider disabling and reenabling the screensaver.

This sets the Screen Saver to "never":

osascript -e 'tell app "System Events" to tell screen saver preferences to set delay interval to 0'

This sets the Screen Saver to 5 minutes:

osascript -e 'tell app "System Events" to tell screen saver preferences to set delay interval to 300'

The interval value is in seconds even though the GUI shows minutes.

If your version of OSX has a slider in the Screen Saver System Preferences, the slider will update. Later versions, like Mountain Lion, have a dropdown with a few enumerated options. This does not update.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.