3

Is there a way to turn screen sleeping on and off temporarily through AppleScript? I'm making a script at the moment that will run for a few minutes when I'm away, so I don't want it to sleep, but don't want to manually do it every time.

4

Certainly the easiest way to accomplish this is by using do shell script. pmset is definitely a viable option, though I am personally partial to the caffeinate command, which doesn't modify any preferences and doesn't require administrator privileges. You could use the following AppleScript to keep your screen awake indefinitely:

do shell script "caffeinate -di"

Alternatively, you can run caffeinate for a specified amount of time, after which your display will be free to go to sleep:

do shell script "caffeinate -dit [time in seconds]"
0

You can use the AppleScript do shell script command with the pmset command to alter the energy saving settings.

The following example disables display sleep:

do shell script "pmset -a displaysleep 0" with administrator privileges

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .