Press "Enter" to skip to content

Linux Quickie: Easy script for switching between multiple Display Configurations

Roberto Leon 0

Backstory (skip the foreplay)

I recently stumbled with a small but annoying situation for a couple of weeks now and decided to invest a couple of minutes to fix it once and for all. I’ve been having a home office for years before COVID-19 since most of my work is done remotely anyway. However, at home, we also have a smaller/temporary setup downstairs I share with my significant other and use two(2) days a week when she has to go to her office. It is simply easier to manage when being alone with the kids @ home working downstairs in an open space near the kitchen, TV, backyard, etc.

I have a four(4) monitor setup on my office workstation, which I never power off and as you can imagine for a tech guy, I have a lot of windows and stuff arranged the way I like on my sessions. In order to keep consistency in my work, I open my KDE session remotely from downstairs using NoMachine, which works almost real-time and in full screen, just like being upstairs in my workstation.

The problem is that this setup is just two(2) monitors and with an awkward resolution, which means that every other day I needed to manually (1) disable two of the monitors, (2) change display resolution, and (3) fight re-arranging windows that got lost, also probably needing to re-connect after each step because sometimes NoMachine did not like the changes on-the-fly. The next day, re-configure again for my full setup… Believe it or not, it came to become a very annoying everyday task.


Note: Most of my computers, including my main workstation setup, run Arch Linux + KDE Plasma, but you should be able to easily google the equivalent commands for your preferred distribution. You can also apply this idea if you often switch between different workspaces with different display configurations.

  • Install ARandR if you don’t already have it. This is for an easy way of getting the xrandr CLI equivalent of your display config using a GUI (if you’re lazy like me):
$ sudo pacman -S arandr
  • Execute ARandR and configure your displays as you like for your first setup. ARandR will automatically bring up your current display settings, so if you prefer to use your desktop environment settings application before opening ARandR, that will also work.
  • Go to Layout => Save As, and save a shell script for your first setup. In my case, I used the default path under my home directory /home/user/.screenlayout. After this, re-arrange your display configuration for your second setup and save the file with a different name.
  • I ended up with the following two(2) files. The generated files are one-liner, but of course, my OCD kicked in and I modified both files for a cleaner and more readable multi-line format:
xrandr \
--output DP-1 --mode 1920x1080 --pos 0x1080 --rotate normal --primary \
--output HDMI-1 --mode 1920x1080 --pos 1920x1080 --rotate normal \
--output DVI-I-1 --mode 1920x1080 --pos 1920x0 --rotate normal \
--output DVI-D-1 --mode 1920x1080 --pos 0x0 --rotate normal
xrandr \
--output DP-1 --mode 1280x1024 --pos 0x56 --rotate normal --primary \
--output HDMI-1 --mode 1920x1080 --pos 1280x0 --rotate normal \
--output DVI-I-1 --off \
--output DVI-D-1 --off
  • Now it’s just a matter of setting up a quick hotkey to invoke either script. I just used the built-in KDE “Custom Shortcuts” GUI to set them up and now I can instantly switch between display configurations:

Subscribe to get notified of new content!

Success! You're on the list.


The views and opinions expressed on this site are my own and do not reflect the views and opinions of my employer. Roberto Leon is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *