#!/bin/bash # External monitor manager: # Profiles are hardcoded to automate connection to know setups. Using # `--list` flag it will list all connected external monitors with # relevant info. MAIN="LVDS-1" declare -A CONNECTED while read -r port edid; do if [[ $port != $MAIN ]]; then CONNECTED+=( ["$port"]="$edid" ) fi done < <(xrandr --prop | awk ' !/^[ \t]/ { if (port && edid) print port, edid port=$1 edid="" } /[:.]/ && rec { sub(/.*000000fc00/, "", edid) edid = substr(edid, 0, 26) "0a" sub(/0a.*/, "", edid) rec=0 } rec { sub(/[ \t]+/, "") edid = edid $0 } /EDID.*:/ { rec=1 } ') if [ "$#" -gt 0 ] && [ "$1" == "--list" ]; then for i in "${!CONNECTED[@]}" do brand=$(xxd -r -p <<< "${CONNECTED[$i]}") echo -e "$i:\t${CONNECTED[$i]}\t($brand)" done else ACTIVE=$(xrandr --listactivemonitors | awk '/^[ \t]/ { print $4 }') # Office config # VGA-1: 44454c4c20503233313748 (DELL P2317H) # DP-2: 44454c4c2055323431324d (DELL U2412M) PROFILE="OFFICE" if [[ ${CONNECTED["VGA-1"]} == "44454c4c20503233313748" ]] && [[ ${CONNECTED["DP-2"]} == "44454c4c2055323431324d" ]]; then if grep -qs "VGA-1" <<< "$ACTIVE"; then xrandr --output VGA-1 --off --output LVDS-1 --auto --output DP-2 --off notify-send "$PROFILE profile: OFF" else notify-send "$PROFILE profile: ON" xrandr --output VGA-1 --auto --rotate left --output DP-2 --auto --right-of VGA-1 --output LVDS-1 --off fi exit 0 fi # Home config # VGA-1: 44454c4c20503232313148 (DELL P2211H) # DP-2: 44454c4c2055323431324d (DELL U2412M) PROFILE="HOME" if [[ ${CONNECTED["VGA-1"]} == "44454c4c2055323431324d" ]]; then if grep -qs "VGA-1" <<< "$ACTIVE"; then xrandr --output VGA-1 --off --output LVDS-1 --auto notify-send "$PROFILE profile: OFF" else notify-send "$PROFILE profile: ON" xrandr --output VGA-1 --auto --output LVDS-1 --auto --left-of VGA-1 fi exit 0 fi notify-send "No matching monitor profile!" fi