From 9f2ecebede044b78848f3ed578cc52aec67a14ee Mon Sep 17 00:00:00 2001 From: vas-dav Date: Sun, 10 Mar 2024 12:37:24 +0200 Subject: [PATCH] xrandr: add utility to switch between monitors --- xrandr/toggle | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 xrandr/toggle diff --git a/xrandr/toggle b/xrandr/toggle new file mode 100755 index 0000000..774a01e --- /dev/null +++ b/xrandr/toggle @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check if both monitor names are provided as arguments +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Define monitor names from command-line arguments +MONITOR_TO_TURN_ON="$1" +MONITOR_TO_TURN_OFF="$2" + +# Check if the monitor to turn on is connected +if xrandr | grep "$MONITOR_TO_TURN_ON connected" > /dev/null; then + # Monitor to turn on is connected, switch monitors + xrandr --output "$MONITOR_TO_TURN_OFF" --off --output "$MONITOR_TO_TURN_ON" --auto + echo "Switched to $MONITOR_TO_TURN_ON and turned off $MONITOR_TO_TURN_OFF." +else + echo "Error: $MONITOR_TO_TURN_ON is not connected." + exit 1 +fi +