I have a Dell Precision M4300 with a Dell Dock PRO1X running Ubuntu Natty.

When I have the laptop docked the lcd display is off and I use two external monitors however when I undock the laptop it does not switch to the laptop screen. The same happens when I dock the laptop, it does not switch to the external monitors.

If I reboot the laptop it will choose the correct setup but it will not automatically change monitors with Ubuntu running.

My Xorg.conf


Dock/UnDock Scripts

I have finally put together a complete script setup that will detect my dock status and switch the monitors automatically.

The first thing I did was to get rid of my Xorg.conf as it caused more issues that it solved. Since I am using an nvdia card I eventually found that using disper was the best way to go. I had discounted it before as its standard commands could not achieve my dualview setup but then I found I could create a custom metamode to use with disper.

To create the custom metamode I used the values stored in Xorg.conf along with previous testing with nv-control-dpy and xrandr as a guide. This metamode and other twinview values were added to a file that can be passed to disper through stdin.

Due to having different sized monitors with Twinview I need to use XCreateMouseVoid, as described in this question.

Below is a complete breakdown of the scripts and files with their contents.


  1. Create XCreateMouseVoid script:

    Script Name: ~/.mousevoid

    echo "Mouse Void"
    /opt/XCreateMouseVoid/XCreateMouseVoid 0 1112 1280 88 &
    /opt/XCreateMouseVoid/XCreateMouseVoid 0 0 1280 88 &

    chmod +x ~/.mousevoid

  2. Create Disper settings file:

    File Name: ~/.disperDocked

    backend: nvidia
    associated displays: CRT-0, DFP-0, DFP-1
    metamode: CRT-0: 1280x1024_60 @1280x1024 +0+88, DFP-1: 1920x1200 @1920x1200 +1280+0
    scaling: default, default, stretched
    xinerama info order: DFP-1, CRT-0, DFP-0
  3. Create the export dbus session script:

    Script Name: ~/.export_x_info

    # Export the dbus session address on startup so it can be used by any other environment
    sleep 5
    touch $HOME/.Xdbus
    chmod 600 $HOME/.Xdbus
    env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
    echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus
    # Export XAUTHORITY value on startup so it can be used by cron
    env | grep XAUTHORITY >> $HOME/.Xdbus
    echo 'export XAUTHORITY' >> $HOME/.Xdbus

    Set to user executable only: chmod 700 ~/.export_x_info

    Then put it in Startup Applications:

    Name: X Environment Variables
    Command: /home/your_user/.export_x_info

    Unless you restart you need to run ~/.export_x_info to create the .Xdbus file

  4. Create the udev rule that will run with upon a dock event:

    Script Name: /etc/udev/rules.d/81-dell-dock.rules

    KERNEL=="dock.0", ACTION=="change", RUN+="/usr/local/sbin/dell-dock"

    chmod +x /etc/udev/rules.d/81-dell-dock.rules

  5. Create the script that is associated with the udev rule:

    Script Name: /usr/local/sbin/dell-dock

    # wait for the dock state to change
    sleep 0.5
    DOCKED=$(cat /sys/devices/platform/dock.0/docked)
    case "$DOCKED" in
           echo "Run UnDocking Script..."
            echo "Run Docking Script..."
    exit 0

    chmod +x /usr/local/sbin/dell-dock

  6. Create the undock script (change your_user to match your user name):

    Script Name: /usr/local/sbin/undock

    export HOME=/home/$USER
    source $HOME/.Xdbus
    export DISPLAY=:0
    echo "UnDocking Script"
    echo "Switch primary monitor"
    sudo -u $USER disper -s
    echo "Killall XCreateMouseVoid"
    pkill XCreate
    echo "Restart conky"
    pkill conky
    sudo -u $USER conky &

    chmod +x /usr/local/sbin/undock

  7. Create the dock script (change your_user to match your user name):

    Script Name: /usr/local/sbin/dock

    export HOME=/home/$USER
    source $HOME/.Xdbus
    export DISPLAY=:0
    echo "Docking Script"
    echo "Switch to Dualview"
    sudo -u $USER disper -i < $HOME/.disperDocked
    echo "Start XCreateMouseVoid"
    pkill XCreate
    sudo -u $USER $HOME/.mousevoid
    echo "Restart conky"
    pkill conky
    sudo -u $USER conky &

    chmod +x /usr/local/sbin/dock


To debug the dock scripts you have to enable udev debug logging:

udevadm control --log-priority=debug

Then open syslog in Log File Viewer


nVidia Readme: Config Twinview, X Config Options
Disper PPA
Ubuntu Forum - Un/Dock Scripts

  • Cas, it was suggested that I comment on your post to ask about the problem that I am having with this: askubuntu.com/questions/68737/auto-switching-with-dock May 16 '12 at 19:28
  • Do you have the script dell-dock.sh?
    – Cas
    Jun 15 '12 at 2:03
  • 1
    Yes it seems that that file does not exist: $ cat /sys/devices/platform/dock.0/docked cat: /sys/devices/platform/dock.0/docked: No such file or directory Jun 20 '12 at 16:41

You can use autorandr.

Auto-detect the connect display hardware and load the appropiate X11 setup using xrandr or disper

Automatically select a display configuration based on connected devices

See also:

  • This solution is painless and works great. Mar 6 '20 at 15:03

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.