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 correspondig xrandr command ?

Or maybe there's another simpler solution ?


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

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.