Skip to content

Instantly share code, notes, and snippets.

@alexanderlz
Last active July 31, 2016 12:26
Show Gist options
  • Save alexanderlz/f9def39af8a5cd640793d5ea8f3ce89d to your computer and use it in GitHub Desktop.
Save alexanderlz/f9def39af8a5cd640793d5ea8f3ce89d to your computer and use it in GitHub Desktop.
Create a helper script that switches monitors when ubuntu laptop docked/undocked
  1. install arandr

    sudo apt-get install arandr

  2. save 2 configurations, one for monitors attached on docking, another for laptop only.

    ~/.screenlayout/dock.sh ~/.screenlayout/undock.sh

  3. add new udev rule:

    vi /etc/udev/rules.d/81-yourlaptop-dock.rules

    KERNEL=="dock.0", ACTION=="change", RUN+="/YOURLOCATION/yourlaptop-dock.sh"

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

  4. create /YOURLOCATION/yourlaptop-dock.sh (a script that should be run by the udev rule)

vi /YOURLOCATION/yourlaptop-dock.sh

    #!/bin/bash
    sleep 1
    DOCKED=$(cat /sys/devices/platform/dock.0/docked)
    case "$DOCKED" in
            "0")
            #undocked event
            ~/.screenlayout/undock.sh
            ;;
            "1")
            #docked event
            ~/.screenlayout/dock.sh
            ;;
    esac
    exit 0
  1. chmod a+x /YOURLOCATION/yourlaptop-dock.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment