I wrote a set-up script for my dual screen set-up some while ago, for when X went bonkers and I needed to restore sanity, but I just found a spare monitor and worked out I can use DP from a USB-C port I didn't know I had.

It suddenly occurred to me that xrandr might be able to create its own command-line for the current set-up, rather than me having to fiddle about writing it myself, but I can't find any options for that.

Is there a utility for this? Is it a stupid idea?


I've had the same problem before which led me to create a function in ~/.bashrc called xreset:

xreset () {

    xrandr --output HDMI-0  --mode 1920x1080 --pos 0x0       --rotate normal \
           --output eDP-1-1 --mode 1920x1080 --pos 3840x2160 --rotate normal \
           --output DP-1-1  --mode 3840x2160 --pos 1920x0    --rotate normal

} # xreset

After you get your monitors arranged by position and resolution, grab the current setup with:

$ xrandr | grep " connected"

HDMI-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 1107mm x 623mm
eDP-1-1 connected primary 1920x1080+3840+2160 (normal left inverted right x axis y axis) 382mm x 215mm
DP-1-1 connected 3840x2160+1920+0 (normal left inverted right x axis y axis) 1600mm x 900mm

All the information is there for you to create your own xreset function.

  • Thanks, but it was that very translation I was looking to automate, and it turns out it's available from arandr, as I mention below. – Tim Baverstock Sep 12 at 13:03
  • Fair enough but for people who don't want to install extra packages this answer helps them I think. – WinEunuuchs2Unix Sep 12 at 15:07

Tut. Sometimes asking the question gets you different search terms.

Arandr is a graphical editor that allows you to move things around, but most pertinently it will save/export xrandr command-lines as scripts:

xrandr \
   --output HDMI-2 --mode 3840x2160 --pos 0x48 --rotate normal \
   --output HDMI-1 --off \
   --output DP-1 --mode 3840x2160 --pos 5760x0 --rotate left \
   --output eDP-1 --primary --mode 1920x1080 --pos 3840x1528 --rotate normal \
   --output DP-2 --off

I don't need the 'off' outputs, but they're harmless.

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.