Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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

share|improve this answer
Cas, it was suggested that I comment on your post to ask about the problem that I am having with this: – Toby Joiner May 16 '12 at 19:28
Do you have the script – Cas Jun 15 '12 at 2:03
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 – Toby Joiner 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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.