While looking if someone asked this question before, I landed on this for Windows.
I'd like to do something similar (shortcut or terminal alias/command) on Linux/Ubuntu to be able to quickly switch the external monitor between landscape and portrait mode instead of having to go to Displays setting it and confirming the configuration.
Jacob Vlijm provided a Python script which works. If you have another idea I'd love to know about it.
Update: I have updated Jacob's script to work for two screens if they are connected.
The script below is to toggle rotation of either one of your screens:
How to use
toggle-rotate.py
In the head section of the script, set:
xrandr
)the rotate direction, either
left
orright
(between quotes, like in the example).Test- run it by the command (two times, from a terminal):
If all works fine, add it to a shortcut key. Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
to a shortcut of your choice...
That's it.
Explanation
In the output of the command
xrandr
, the current rotation of your screen (if any) is mentioned directly after the screen's position, for example:In the example, we see:
1024x1280+1680+0 left
. The script looks into the line, corresponding to the screen, mentioned in the head of the script. if the screen is rotated, the script runs the (xrandr
) command:if not, it runs (for example):
To rotate the screen counter-clockwise
I have been using Jacob's script. However I am now using an adapter so I want to be able to toggle the orientation whether the monitor is connected to HDMI or through the adapter. For this I modified Javob's script and borrowed another function he wrote: