!/usr/bin/env bash USER="$(who | grep :0\) | cut -f 1 -d ' ')" echo USER ${USER} sudo chown operator:operator /home/operator/hdmi-toggle.log echo HDMI-TOGGLE >>/home/operator/hdmi-toggle.log export XAUTHORITY=/home/$USER/.Xauthority export DISPLAY=:0 ########### Settings ########### # Use 'xrandr' to find these #DP="DP-1" #VGA="VGA-1" HDMI="HDMI-1" #INTERNAL_DISPLAY="LVDS-1" # Check /sys/class/drm for the exact location #DP_STATUS="$(cat /sys/class/drm/card0-DP-1/status)" #VGA_STATUS="$(cat /sys/class/drm/card0-VGA-1/status)" HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)" echo ${HDMI_STATUS} >>/home/operator/hdmi-toggle.log # Do no change! EXTERNAL_DISPLAY="" # Check to see if the external display is connected if [ "${DP_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$DP fi if [ "${VGA_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$VGA fi if [ "${HDMI_STATUS}" = connected ]; then EXTERNAL_DISPLAY=$HDMI fi # The external display is connected if [ "$EXTERNAL_DISPLAY" != "" ]; then # Set the display settings xrandr xrandr --output HDMI-1 --auto # xrandr -s 1368x768 else # Restore to single display xrandr --output HDMI-1 --off fi exit 0