3

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:

#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
    then
        xrandr --output VGA --auto;
        xrandr --output LVDS --off;
    else
        xrandr --output LVDS --auto;
fi

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.

0

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

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.