Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
1  
See this question for an example. –  Nathan Osman Dec 16 '10 at 3:26

1 Answer 1

up vote 6 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.

#!/bin/bash 

ALREADY_SHUTOFF="yes"

while true; do

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

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

            # this command turns off the display
            xset dpms force off
        fi


        ALREADY_SHUTOFF="yes"

    else

        ALREADY_SHUTOFF="no"
    fi

    sleep 10

done
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

 
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.