Skip to content

Instantly share code, notes, and snippets.

@livelace
Created March 12, 2019 18:57
Show Gist options
  • Save livelace/cf40b37ca0618100010c7ea998c09b15 to your computer and use it in GitHub Desktop.
Save livelace/cf40b37ca0618100010c7ea998c09b15 to your computer and use it in GitHub Desktop.
DDC (Display Data Channel) switcher
#!/usr/bin/env bash
# This script acts as a switcher between video inputs of a monitor (https://en.wikipedia.org/wiki/Display_Data_Channel).
# It allows to switch to a custom video input and get back in one key pressing.
#
# Dependencies:
# 1. ddcutil
# Example:
#
# I use this script with two DELL U2415 which are connected through DisplayPort to Dell E-Port Plus.
#
# Example shortcut:
#
# First press -> Ctrl+Alt+Num9 -> /opt/toolset/ddc.sh 1 4 -> switch monitor1 to input4
# Second press -> Ctrl+Alt+Num9 -> /opt/toolset/ddc.sh 1 4 -> switch monitor1 to input2 (where I usually work)
MONITOR="$1"
INPUT="$2"
if [ ! "$MONITOR" ] || [ ! "$INPUT" ];then
echo "ERROR: Usage $0 1|2 1|2|3|4"
exit 1
fi
CURRENT_INPUT=$(printf "0%s\n" $(ddcutil -t -d "$MONITOR" getvcp 0x60 2>/dev/null | cut -d " " -f 4))
case "$INPUT" in
1)
INPUT_CODE="0x0f"
;;
2)
INPUT_CODE="0x10"
;;
3)
INPUT_CODE="0x11"
;;
4)
INPUT_CODE="0x12"
;;
esac
if [ "$CURRENT_INPUT" = "0x10" ];then
# If we are on the primary input - switch to the specific input
ddcutil -d "$MONITOR" setvcp "0x60" "$INPUT_CODE" 2>/dev/null
else
# If we are not on the primary input - switch back to the primary input
ddcutil -d "$MONITOR" setvcp "0x60" "0x10" 2>/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment