I have a lenovo thinkpad with nvidia optimus and a mini docking station series 3.

I want that while docked, it should automatically switch to an external monitor if possible and if I undock it, it should switch to the thinkpad lcd automatically.

This should also work on the boot stage because there I have to type in a password for the encrypted disk (dm-crypt).

I tried the following but it doesn't work:

I created a file /etc/acpi/thinkpad-undock.sh (+ chmod a+x thinkpad-undock.sh) which contains the following lines:

xrandr --output LVDS-1 --auto --output DP-5.8 --off

And also /etc/acpi/thinkpad-dock.sh

prime-select nvidia # ensures that nvidia card is selected
xrandr --output LVDS-1 --off --output DP-5.8 --auto

And again chmod a+x thinkpad-dock.sh.

Executing both scripts manually works.

Than I created two files for handling the events:


event=ibm/hotkey LEN0068:00 00000080 00004010

and also thinkpad-undock-lenovo

event=ibm/hotkey LEN0068:00 00000080 00004011

Then I reloaded the acpi daemon with /etc/init.d/acpid reload. However if I dock or undock the laptop it does nothing.

I got the event number above by executing acpi_listen and then docking and undocking the laptop.

So are there any ideas of how to make it work.

Maybe the problem is solved by some desktop environment for example kde, but I am using xmonad and nevertheless, as indicated above, it should work even on boot stage independently of the desktop environment.

I am running ubuntu 16.04 with kernel version 4.4.0-22.

I tried also to add an udev rule as follow but it didn't work:

ENV{EVENT}=="undock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="disper -s"
ENV{EVENT}=="dock", KERNEL=="dock.0", SUBSYSTEM=="platform", RUN+="disper -s"

I just noticed that the file dock has always the value 0, regardless if the laptop is docked or undocked.

4 Answers 4


Your script doesn't set the DISPLAY environment variable. It should look like this:

export DISPLAY=:0
xrandr --output LVDS-1 --auto --output DP-5.8 --off
  • Thanks. I tried it but it doesn't work. I also don't see why this should be the mistake since the script works (with and without the export statement) if I execute it directly. I rather guess that the script isn't executed by acpid.
    – student
    Jun 27, 2016 at 19:42
  • 1
    It may not have solved your issue, but the DISPLAY var must be set correctly to work - start a terminal in your Xsession (both in docked and undocked configs) and check what the variable is set to there. Note that your terminal is running in a different environment from your acpi scripts.
    – symcbean
    Jun 12, 2023 at 10:56

I've had luck with setting both DISPLAY and XAUTHORITY as well as adding a small sleep, e.g.

export DISPLAY=:0
export XAUTHORITY=/home/user/.Xauthority
sleep 3
xrandr ...

I have a similar setup, however I never chased the solution of reacting to the dock. It's an interesting one.

What I do instead is use Gnome's display manager to set the LCD display to 'off' and the external display to be the primary one. This way whenever I set down the laptop on the dock, it switches over to the external display. When I lift it, it swaps back to the LCD.

Having this on the console (booting off a dm-crypt installation) also works but it has its nuances. If the lid is closed, I set the laptop on the dock and turn it on, it automatically boots on the external display (everything, including BIOS screens, the lot). If the lid is open, it will only swap over after logging in on GDM.


You need something like this:

udev (change idVendor from lsusb)

    ACTION=="add", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="****", RUN+="/local/run.sh /local/udev-dplink-on.sh"
    ACTION=="remove", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="****", RUN+="/local/run.sh /local/udev-dplink-off.sh"

apt-get install at



    echo $1 | at now

more on https://www.eovao.com/en/a/Display%20Link%20Dock%20Ubuntu%20Linux/6/displaylink-dock-in-ubuntu-with-kvm-switch-usb-3.0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .