Last active
February 11, 2024 16:27
-
-
Save cornercase/5ed1a25e9ecfbad2794c0b90b13908bd to your computer and use it in GitHub Desktop.
A shell script to act like a KVM switch using DDC controls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1 - Install ddcctl and/or ddccontrol | |
Step 2 - figure out your input source values for your monitor(s) | |
Step 3 - map those commands to some hotkeys in your OS(es) | |
Step 4 - Probs get a cheap USB switch for keyboard and mouse sharing | |
Step 5 - Profit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: github.com/cornercase | |
# Written: August 8, 2020 | |
# License: WTFPL | |
# Dependecies | |
# MacOS | |
# ddcctl - for MacOS - https://github.com/kfix/ddcctl | |
# Linux | |
# ddccontrol - for linux - https://github.com/ddccontrol/ddccontrol | |
: ' | |
My little scratchpad | |
# for Dell P2213 monitor | |
using ddcctl, input IDs are | |
- VGA = 1 | |
- DVI = 3-14 | |
- DisplayPort = 15-17 | |
Dell P2213 EDID Serial FJ44J3CHAY6S is the left monitor (ie main). | |
- Linux - /dev/i2c-1 = left monitor (VGA) | |
- MacOS - 1 = left monitor (DVI) | |
Dell P2213 EDID Serial FJ44J26IAJ8S is the right monitor (ie secondary) | |
- Linux - /dev/i2c-5 = right monitor (DVI) | |
- MacOS - 2 = right monitor (Displayport) | |
' | |
# are we in MacOS or Linux? | |
if command -v ddccontrol &> /dev/null | |
then | |
echo "ddccontrol found, we're in linux" | |
OS='linux' | |
MONITORS=('/dev/i2c-1' '/dev/i2c-5') | |
fi | |
if command -v ddcctl &> /dev/null | |
then | |
echo "ddcctl found, we're in macos" | |
OS='mac' | |
MONITORS=(1 2) | |
fi | |
# set mac mini inputs to DVI-D on monitor 1, displayport on monitor 2 | |
if [ $1 = 'mm' ] | |
then | |
SOURCES=(3 15) | |
fi | |
# set desktop inputs to VGA on monitor 1, DVI-D on monitor 2 | |
if [ $1 = 'dt' ] | |
then | |
SOURCES=(1 3) | |
fi | |
if [ ${#MONITORS[*]} -ne ${#SOURCES[*]} ] | |
then | |
echo "Number of monitors (${#MONITORS[*]}) doesn't equal number of sources ${#SOURCES[*]}" | |
exit | |
fi | |
for index in ${!MONITORS[*]} | |
do | |
case $OS in | |
'mac' ) | |
ddcctl -d ${MONITORS[$index]} -i ${SOURCES[$index]} | |
;; | |
'linux' ) | |
sudo ddccontrol -r 0x60 -w $${SOURCES[$index]} dev:${MONITORS[$index]} | |
;; | |
esac | |
done | |
#sudo ddccontrol -r 0x60 -w 15 dev:/dev/i2c-5 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
Author
cornercase
commented
Aug 8, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment