Skip to content

Instantly share code, notes, and snippets.

@timmc
Created July 30, 2014 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/b74ee7307377d38a842b to your computer and use it in GitHub Desktop.
Save timmc/b74ee7307377d38a842b to your computer and use it in GitHub Desktop.
monitor-autodetect.sh
#!/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