Last Updated: February 25, 2016
·
565
· lkartono

Ubuntu : define the primary display screen using a script

We sometimes for some reasons, cannot access the Ubuntu settings dashboard allowing us to configure the way we want our system to work, and more particularly, which screen is our primary display, if like me you are using 2 screens.

So what do you do when you want to switch screens but cannot access this settings dashboard? Well, today I'm gonna show you how to do it using a really handy script.

In case of multiple screens, we first need to display the list of connected screens, so we can then choose the one we want to use as primary :

#!/bin/bash
echo "Enter the primary display from the following : "
xrandr --prop | grep "[^dis]connected" | cut --delimiter=" " -f1

This will display a list which will looks like :

DVI-I-1
HDMI-1

Then the script need to read the choice we've made. To stay simple here, we will need to type either DVI-I-1 or HDMI-1 :

read screen_choice # Will store the selected screen within the variable screen_choice

Finally, we can set which screen we will be using as primary display :

xrandr --output $screen_choice --primary

Here is the full script :

#!/bin/bash
echo "Enter the primary display from the following : "
xrandr --prop | grep "[^dis]connected" | cut --delimiter=" " -f1
read screen_choice
xrandr --output $screen_choice --primary