Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

When I invoke the "Lock Screen" action, is there a way to have the monitor go to sleep instantly? I'm aware of the power management setting to turn off the display after a set amount of time, but I want this to happen immediately.

I'm hoping there is a bash script that will lock the screen and put the display to sleep, and that I can have this invoked when a screen lock operation occurs.

share|improve this question
See this question for an example. –  Nathan Osman Dec 16 '10 at 3:26

1 Answer 1

up vote 7 down vote accepted

The following script will check every ten seconds to see if the screensaver is enabled, and if it is, turn of the display using the command xset dpms force off.

It also checks to make sure it didn't already turn off the display, so you can unlock the screen without the monitor turning off while you are typing your password.



while true; do

    if (gnome-screensaver-command -q | grep "is active");

        echo $ALREADY_SHUTOFF
        if [ "$ALREADY_SHUTOFF" == "no" ];

            # this command turns off the display
            xset dpms force off




    sleep 10

share|improve this answer
I tried xset dpms force off and it does shut off the display, but then it turns back on again after a few seconds. –  Nathan Osman Dec 16 '10 at 3:55

Your Answer


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.