Advertisement
constantin-net

monitor switch test

May 4th, 2021 (edited)
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. output_xrandr="$(xrandr)"
  4. active_list=($(xrandr --listactivemonitors | grep '+' | awk {'print $4'}))
  5. disconnected=($(echo "$output_xrandr"| grep 'disconnected' | awk {'print $1'}))
  6. if [[ -n "$disconnected" ]]; then
  7.     for ((i=0; i < ${#disconnected[@]}; i++)); do
  8.     echo "disconnected: ${disconnected[$i]}"
  9.     done
  10. fi
  11. connected="$(echo "$output_xrandr"| grep ' connected')"
  12. primary="$(echo "$connected"| grep 'primary' | awk {'print $1'})"
  13. echo "primary: $primary"
  14. connected_list=($(echo "$connected"| awk {'print $1'}))
  15. inactive_list=""
  16. status=""
  17. count_inactive=0
  18. for ((i=0; i < ${#connected_list[@]}; i++)); do
  19.     for ((k=0; k < ${#active_list[@]}; k++)); do
  20.         if [[ ${active_list[$k]} != ${connected_list[$i]} ]]; then
  21.             status="inactive"
  22.         else
  23.             status="active"
  24.             break
  25.         fi
  26.     done
  27.     if [[ $status == "inactive" ]]; then
  28.         inactive_list[$count_inactive]=${connected_list[$i]}
  29.         ((count_inactive=count_inactive+1))
  30.     fi
  31. done
  32. echo "active: $active_list"
  33. echo "inactive: $inactive_list"
  34. exit 0
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement