Created
July 30, 2014 14:12
-
-
Save timmc/b74ee7307377d38a842b to your computer and use it in GitHub Desktop.
monitor-autodetect.sh
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 | |
# Monitor autodetection. $1 may be once, loop, stop, or resume. | |
stopfile="/home/timmc/.stop-monitor-autoupdate" | |
function autoupdate() { | |
xrandr -q | grep '^VGA1 connected ' > /dev/null | |
if [ $? -eq 0 ]; then | |
xrandr --output LVDS1 --off --output VGA1 --auto | |
else | |
xrandr --output LVDS1 --auto --output VGA1 --off | |
fi | |
} | |
function loop_autoupdate() { | |
for (( ; ; )) | |
do | |
if [ ! -e "$stopfile" ]; then | |
autoupdate | |
fi | |
sleep 3s | |
done | |
} | |
case "$1" in | |
once) | |
autoupdate | |
;; | |
loop) | |
loop_autoupdate | |
;; | |
stop) | |
touch "$stopfile" | |
;; | |
resume) | |
rm "$stopfile" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment