7

I am starting to work with 2 displays on Ubuntu. One of them is rotateable, so I can use it easily in both landscape and portrait mode. But I world prefer to have ability to change orientation setting (which could be found in System Settings->Desktop) from terminal or script on one display but don't rotate other one.

I am pretty sure it is possible via xrandr!

4
  • Is your question mainly on how to script it, or how to do it with xrandr? In the last case, you will find it here: askubuntu.com/a/171154/72216, but it can be made changeable / toggle with a key combination of course, but then the scripting is actually the question. Dec 21, 2014 at 9:31
  • @JacobVlijm as I just found answer on my own from man. Thanks. I think that bash script with xrandr command inside will work, won't it? Dec 21, 2014 at 9:38
  • Absolutely. The nicest would be to toggle; make a script read from xrandr what is the current rotation of the second screen, set it to "the other option" under a shortcut key. Dec 21, 2014 at 9:42
  • 1
    @JacobVlijm I did it, using basicly xrandr and grep. Dec 21, 2014 at 18:20

2 Answers 2

11

Strange, but I found answer first!

You use

$ xrandr --output $monitorName --rotate $direction

where $monitorName can be found in output of

$ xrandr

and $direction is left for counter-clockwise or right for clockwise.

Edit: Using grep, it is possible to write a script like this:

#!/bin/bash

screen="HDMI1"

descr=$(xrandr | grep "$screen")
if echo "$descr" | grep disconnected
then
        echo "No $screen connected"
        exit 1
fi

alt="left"
if echo "$descr" | grep --quiet -P "^[^(]*$alt"
then
        rotate="normal"
else
        rotate="$alt"
fi
xrandr --output $screen --rotate $rotate 

which actually switches orientation of monitor storaged in $screen variable, and $alt is the alternative orientation.

1
  • 1
    nice, and it works! Dec 21, 2014 at 18:32
6

You'll need to use xrandr for that.

xrandr -o $orientation

Where $orientation is left, right, inverted, or normal.

You can select the display you want to rotate with the --display option.

1
  • --dsplay selects X server, not the monitor, does it? Dec 21, 2014 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.