Skip to content

Instantly share code, notes, and snippets.

@jimrybarski
Created October 3, 2018 16:33
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 jimrybarski/989aa4afbf176bde7006fe27d9a56266 to your computer and use it in GitHub Desktop.
Save jimrybarski/989aa4afbf176bde7006fe27d9a56266 to your computer and use it in GitHub Desktop.
#!/bin/bash
# modified from https://faq.i3wm.org/question/5312/how-to-toggle-onoff-external-and-internal-monitors.1.html
# this script will toggle which monitors are on. after booting, all monitors will be clones of the main laptop monitor.
# after each execution, we cycle through the following modes:
# - external monitor only (work mode)
# - external and laptop on but not clones (presentation mode)
# - laptop monitor only
# we need to include aliases so we can use the commands to adjust screen brightness
shopt -s expand_aliases
source ~/.aliases
EXTERNAL_OUTPUT="HDMI-1"
INTERNAL_OUTPUT="eDP-1"
# both monitors are on by default after boot
if [ ! -f "/tmp/monitor_mode.dat" ] ; then
monitor_mode="all"
# otherwise read the value from the file
else
monitor_mode=`cat /tmp/monitor_mode.dat`
fi
if [ $monitor_mode = "all" ]; then
monitor_mode="EXTERNAL"
day
xrandr --output $INTERNAL_OUTPUT --off --output $EXTERNAL_OUTPUT --auto
elif [ $monitor_mode = "EXTERNAL" ]; then
monitor_mode="PRESENTATION"
projector
xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto --left-of $INTERNAL_OUTPUT
else
monitor_mode="all"
night
xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off
fi
echo "${monitor_mode}" > /tmp/monitor_mode.dat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment