Saturday 5 January 2013

External display hotplug (on linux, with xrandr)

Every morning when I would come to the office, I would place my laptop on the desk and connect the power, network cable and the external display. And every time I'd have to go through the same external display configuration dialog. And that's just annoying. So I decided to automate. Isn't that a thrilling word? Automate.

A friend helped me write a shell script to enable or disable a twin display configuration using xrandr, and I set it up to be triggered by UDEV when an external display is hotplugged on the VGA port.

This is the script:

The two things you will probably want to change are the constants EXTERNAL_POSITION and BUILTIN_BASE. If you want the external display to show a mirror of your primary display, use setting EXTERNAL_POSITION="same-as".

I placed the script in /usr/local/lib/ and set up an UDEV rule that triggers it when an external display is connected.

This is my UDEV rule, in /etc/udev/rules.d/:

When you add the UDEV rule, you must reload rules for the changes to take effect. You do it by saying

$ sudo udevadm control --reload-rules

And that's it. Enjoy!



No comments:

Post a Comment