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.


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]"

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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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