# If an external monitor is connected, place it with xrandr function determineLocation() { local extLoc=$1 local intOut=$2 case "$extLoc" in left|LEFT) OPTIONS="--left-of $intOut" ;; right|RIGHT) OPTIONS="--right-of $intOut" ;; top|TOP|above|ABOVE) OPTIONS="--above $intOut" ;; bottom|BOTTOM|below|BELOW) OPTIONS="--below $intOut" ;; *) OPTIONS="--above $intOut" ;; esac } function setupMonitor() { local intOut=$1 local extOut=$2 local options=$3 xrandr | grep $extOut | grep " connected " if [ $? -eq 0 ]; then #printf "INTERNAL_OUTPUT: %s, EXTERNAL_OUTPUT: %s, OPTIONS: %s\n" "$intOut" "$extOut" "$options" xrandr --output $intOut --auto --output $extOut --auto $options # Alternative command in case of trouble: # (sleep 2; xrandr --output $intOut --auto --output $extOut --auto $options) & else #printf "INTERNAL_OUTPUT: %s, OPTIONS: %s\n" "$intOut" "$options" xrandr --output $intOut --auto --output $options --off fi } INTERNAL_OUTPUT="LVDS1" # External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1" EXTERNAL_OUTPUT="VGA1" # EXTERNAL_LOCATION may be one of: left, right, above, or below EXTERNAL_LOCATION="above" determineLocation "$EXTERNAL_LOCATION" "$INTERNAL_OUTPUT" setupMonitor "$INTERNAL_OUTPUT" "$EXTERNAL_OUTPUT" "$OPTIONS" # External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1" EXTERNAL_OUTPUT="HDMI1" # EXTERNAL_LOCATION may be one of: left, right, above, or below EXTERNAL_LOCATION="right" determineLocation "$EXTERNAL_LOCATION" "$INTERNAL_OUTPUT" setupMonitor "$INTERNAL_OUTPUT" "$EXTERNAL_OUTPUT" "$OPTIONS"