I want to write a script to clone my current desktop to another monitor, but I can't get the second monitors resolution to be set to the resolution of the primary monitor.

How can I automatically set the resolution of the second monitor to be the same as the first monitor?


It depends on what is the output of your xrandr when both monitors are connected. If it is for example something like this:

$ xrandr
Screen 0: minimum 320 x 200, current 1400 x 1050, maximum 1400 x 1400
VGA disconnected (normal left inverted right x axis y axis)
LVDS connected 1400x1050+0+0 (normal left inverted right x axis y axis) 286mm x 214mm
   1400x1050      60.0*+   50.0  

Then you can use sed to get the resolution of your primary monitor (here LVDS) and set that to your secondary monitor (here VGA):

RESOLUTION=$(xrandr | sed -nr 's/LVDS connected ([0-9]+x[0-9]+).*/\1/p')
xrandr --output VGA --mode $RESOLUTION

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.