I'm new to bash scripting, and I'm trying to configure my video outputs so that my laptop display gets turned off when I connect an external monitor via VGA.

That's the script I came up with, pretty straightforward:

myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
        xrandr --output VGA --auto;
        xrandr --output LVDS --off;
        xrandr --output LVDS --auto;

All is working as it should except for the xrandr --output LVDS --off bit, as my laptop display simply adjusts its resolution to match the external monitor's one and stays on.

Can't figure out the bug on this one. Any help is appreciated.


Does --output LVDS --off work correctly when run directly from the shell?

Can you swap the lines in the then-part? Maybe there are some timing issues?

  • Yes, the command works properly when given from shell. I should have mentioned that. Also, swapping the lines has no effect whatsoever. So, no timing issues here.
    – zool
    Mar 26 '14 at 14:45

Try using xset command (https://linux.die.net/man/1/xset ).

Instead of:

xrandr --output LVDS --off

use something like:

xset -display :0 dpms force off

I'm assuming that :0 is your laptop display.

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.