I have a laptop with Ubuntu 15.04 installed and an external VGA monitor connected and I usually turn my laptop screen off and use only the external monitor, but whenever I want to use only the laptop screen I need to go through the tedious routine of clicking preferences>displays>external monitor:off> built-in screen: on, so I thought about writing a simple script to do this for me and create a shortcut from my desktop so I can swap monitors by clicking an executable. How can I write a script to accomplish the following tasks?

1- detect which monitors are on or off;
2- if built-in screen is on, turn it off and turn external monitor on; else, turn external monitor off and built-in screen on;

I tried this:


#swap from external monitor to laptop screen
xrandr --output LVDS-0 --auto
xrandr --output VGA-0 --off

#swap from laptop screen to external monitor
#xrandr --output VGA-0 --auto
#xrandr --output LVDS-0 --off

but the terminal returns me an error:"warning: output LVDS-0 not found; ignoring". Could someone help? Thanks in advance.

  • Could we get the output of xrandr? That should tell you the correct display names.
    – derobert
    Oct 6, 2015 at 16:35

1 Answer 1


The easiest solution would probably be to install a front-end for xrandr, e.g. arandr, set whatever you want to set there and save the settings as a script (there is an option like this in arandr, I've used it), then use it as a template for your script. This is likely to get all the names and other stuff correct.


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.