2

I have a Lenovo X220 with a dock and external screen. Right now I have to launch a xrandr shortcut by hand to use the screen I want, depending on the situation.

For example :

  • Docked : xrandr with external screen output
  • Not docked : xrandr with laptop screen output

I was wondering how to do this automatically, maybe with help of lsusb's output? When the laptop is docked it lists Lenovo ThinkPad Mini Dock Plus Series 3, is there a way to detect that and then run the corresponding xrandr command?

Or maybe there's another simpler solution?

AdminBee
  • 21,637
  • 21
  • 47
  • 71
mike23
  • 155
  • 3

1 Answers1

3

You can use udev:

# /etc/udev/rules.d/<priority>-<name>.rules

ACTION=="add", BUS="usb", SYSFS{serial}="<serial-number>", NAME="<name>", RUN="/your/xrandr/script"

(e.g. <priority> might be 50 and <name> docked-monitor)

Where the SYSFS and NAME settings come from lsusb. Other options to target the particular device (your dock) are available, see the man page (linked above) for what's most convenient to you.

Then reload to take effect:

$ udevadm control --reload-rules
OJFord
  • 1,838
  • 1
  • 16
  • 26