Last active
December 11, 2021 23:40
-
-
Save sophieforceno/104af28756ceb0afa840 to your computer and use it in GitHub Desktop.
A Bash script that switches between two displays depending on display connectivity
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 | |
# dispd: Display Switcher daemon v1.0-(092015) | |
# by Sophie Forceno | |
# | |
# dispd will enable and make active one of two displays depending on which is plugged in | |
# Currently, allows you to switch between native laptop display and external HDMI monitor | |
# Execute 'dispd &' to run in background | |
# Then, plug/unplug your external display and watch the magic happen! | |
# | |
# Distributed under an "I-don't-care-what-you-do-with-this" license | |
# Change these depending on system configuration | |
INT="LVDS1" | |
EXT="HDMI1" | |
# Main loop | |
while true | |
do | |
# Change these depending on system configuration | |
LVDS=$(cat /sys/class/drm/card0-LVDS-1/enabled) | |
HDMI=$(cat /sys/class/drm/card0-HDMI-A-1/status) | |
if [[ $HDMI = "connected" ]]; then | |
# Commented out because it is unique to my system configuration | |
# You may not need it | |
#xrandr --addmode HDMI1 1920x1080 | |
# Change --mode or remove it depending on your configuration | |
xrandr --output $INT --off --output $EXT --mode 1920x1080 | |
elif [[ $HDMI = "disconnected" ]] && [[ $LVDS = "disabled" ]]; then | |
# Change or remove --mode depending on your cnofiguration | |
xrandr --output $INT --mode 1280x800 --output $EXT --off | |
fi | |
# Sleep = 1s produces the least delay possible | |
sleep 1s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment