Skip to content

Instantly share code, notes, and snippets.

@rn0
Last active November 2, 2022 10:09
Show Gist options
  • Save rn0/e8be0a51e834f0a4e73faf245ec9c762 to your computer and use it in GitHub Desktop.
Save rn0/e8be0a51e834f0a4e73faf245ec9c762 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o nounset
set -o errexit
[[ "$EUID" -eq 0 ]] || exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
declare -A source=( [0x0f]="DP" [0x11]="HDMI" )
declare -A inputMap=( [0x0f]=0x11 [0x11]=0x0f )
monitor1=$(ddcutil getvcp --display 1 60 | sed -n "s/.*(sl=\(.*\))/\1/p")
monitor2=$(ddcutil getvcp --display 2 60 | sed -n "s/.*(sl=\(.*\))/\1/p")
echo "Monitor 1 = ${source[$monitor1]}; Monitor 2 = ${source[$monitor2]}"
monitor1NewInput=${inputMap[$monitor1]}
monitor2NewInput=${inputMap[$monitor2]}
echo "Monitor 1 = ${source[$monitor1NewInput]}; Monitor 2 = ${source[$monitor2NewInput]}"
ddcutil setvcp --display 1 60 $monitor1NewInput
ddcutil setvcp --display 2 60 $monitor2NewInput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment