Use external monitor automatically, when started in Docking Station
Solution 1:
There are some tools to automate it like RandR, disper, displex or this one http://gnomefiles.org/content/show.php/Laptop+external+display+hotplugging?content=138742
Solution 2:
I adjusted myself a script I found to my needs.
You can ignore the wacom commands. Those are just to match the input layer of the tablet to the screen orientation.
#!/bin/bash
#!/bin/sh
# wait for the dock state to change
sleep 2.0
DOCKED=$(cat /sys/devices/platform/dock.0/docked)
case "$DOCKED" in
"0")
#undocked event - lets remove all connected outputs apart from LVDS
for output in $(/usr/bin/xrandr -d :0.0 --verbose|grep " connected"|grep -v LVDS|awk '{print $1}')
do
/usr/bin/xrandr -d :0.0 --output $output --off
done
xrandr --output LVDS1 --rotation normal
xsetwacom set "Wacom ISDv4 90 Pen stylus" MapToOutput LVDS1
xsetwacom set "Wacom ISDv4 90 Pen eraser" MapToOutput LVDS1
# rotates the tablet input to the according position (half=180°, (c)cw=(counter)clockwise, none=normal)
xsetwacom set "Wacom ISDv4 90 Pen stylus" rotate none
# if multiouch present set: xsetwacom set "Wacom ISDv4 E6 Finger touch" rotate half
xsetwacom set "Wacom ISDv4 90 Pen eraser" rotate none
;;
"1")
## rotates internal Laptop Display LVDS1 to inverted
xrandr --output HDMI2 --auto --above LVDS1
xrandr --output LVDS1 --rotation inverted
xsetwacom set "Wacom ISDv4 90 Pen stylus" MapToOutput LVDS1
xsetwacom set "Wacom ISDv4 90 Pen eraser" MapToOutput LVDS1
# rotates the tablet input to the according position (half=180°, (c)cw=(counter)clockwise, none=normal)
xsetwacom set "Wacom ISDv4 90 Pen stylus" rotate half
# if multiouch present set: xsetwacom set "Wacom ISDv4 E6 Finger touch" rotate half
xsetwacom set "Wacom ISDv4 90 Pen eraser" rotate half
;;
esac
exit 0
It identifies a status file in /sys/devices/platform/dock.0 wheter it has the value 1 for docked or 0 for undocked an triggers xrandr to adjust the display output to an extended dektop using the inbuilt display LVDS1 an configuring the external display HDMI2 above.