Created
April 22, 2024 20:37
-
-
Save hunterjsb/671497551c08fb4b1fe2ac9a810e18b7 to your computer and use it in GitHub Desktop.
Toggle Monitors One/All
This file contains hidden or 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 | |
| echo "Debug: Starting monitor toggle script" | |
| # Get the current state of the monitors | |
| monitors=$(xrandr --query | grep " connected" | awk '{print $1}') | |
| echo "Debug: Connected monitors: $monitors" | |
| # Check if all monitors are in use | |
| all_on=0 | |
| for monitor in $monitors; do | |
| status=$(xrandr --query | grep "^$monitor" | grep -c "+") | |
| all_on=$((all_on + status)) | |
| done | |
| echo "Debug: Number of monitors in use: $all_on" | |
| if [ "$all_on" -eq "4" ]; then | |
| echo "Debug: All monitors are in use" | |
| # Turn off all monitors except the primary one | |
| primary_monitor=$(xrandr --query | grep " connected primary" | awk '{print $1}') | |
| echo "Debug: Primary monitor: $primary_monitor" | |
| for monitor in $monitors; do | |
| echo "Debug: Processing monitor: $monitor" | |
| if [ "$monitor" != "$primary_monitor" ]; then | |
| echo "Debug: Turning off monitor: $monitor" | |
| xrandr --output "$monitor" --off | |
| else | |
| echo "Debug: Skipping primary monitor: $monitor" | |
| fi | |
| done | |
| echo "Monitors turned off except the primary one." | |
| else | |
| echo "Debug: Not all monitors are in use" | |
| # Turn on all monitors | |
| for monitor in $monitors; do | |
| echo "Debug: Turning on monitor: $monitor" | |
| xrandr --output "$monitor" --auto | |
| done | |
| echo "All monitors turned on." | |
| fi | |
| echo "Debug: Monitor toggle script completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment