fork download
  1. #!/bin/bash
  2. #
  3. # display-find.sh - Script to find a specific connected dislay
  4. # and apply configuration settings to it.
  5.  
  6. # Customize the display to find with the name and model and the
  7. # first 16 bytes of your display EDID. That's the first line of
  8. # the displays EDID you may find with the shell command: xrandr.
  9. DISPLAY_NAME="Display brand and model name"
  10. DISPLAY_EDID="00ffffffffffff004861000000000000"
  11.  
  12. # Customize the action to apply to the display
  13. DISPLAY_ACTION=("setting resolution to 1080i" "--mode 1920x1080i")
  14.  
  15. # Runtime: do not edit the following unless you know what you're doing. :)
  16.  
  17. # Find connected display outputs
  18. OUTPUTS=($(xrandr | grep " connected" | cut -f 1 -d " "))
  19. OUTPUTS_COUNT=${#OUTPUTS[*]}
  20.  
  21. # If no connected display is found exit with error
  22. if [ $OUTPUTS_COUNT -eq 0 ]; then
  23. echo "display-find: error! no display was found, check your cables, exiting..."
  24. exit 1 # Exit error 1: no displays found
  25. fi
  26.  
  27. # Echo found connected displays
  28. echo "display-find: found $OUTPUTS_COUNT displays connected at outputs: ${OUTPUTS[*]}"
  29.  
  30. # Find each connected display's EDID first 16 bytes
  31. OUTPUTS_EDID=($(xrandr --prop | grep -A 1 "EDID:" | cut -f 1 -d "-" | cut -f 2 -d ":"))
  32.  
  33. # For each found EDID check if matches the display to find then
  34. # apply action and exit, else exit with error
  35. COUNTER=0
  36. for EDID in ${OUTPUTS_EDID[*]}; do
  37. if [ $EDID == $DISPLAY_EDID ]; then
  38. DISPLAY_OUTPUT=${OUTPUTS[COUNTER]}
  39. echo "display-find: found match at $DISPLAY_OUTPUT: $DISPLAY_EDID"
  40. echo "display-find: found $DISPLAY_NAME"
  41. echo "display-find: ${DISPLAY_ACTION[0]}"
  42. sleep 1
  43. xrandr --output $DISPLAY_OUTPUT ${DISPLAY_ACTION[1]}
  44. if [ $? -eq 0 ]; then
  45. echo "display-find: done! exiting..."
  46. exit 0 # Exit error 0: Ok
  47. else
  48. echo "display-find: error! applying settings failed. exiting..."
  49. exit 2 # Exit error 2: settings failed
  50. fi
  51. else
  52. ((COUNTER++))
  53. if [ $COUNTER -eq $OUTPUTS_COUNT ]; then
  54. echo "display-find: sorry, no match found for EDID: $DISPLAY_EDID. exiting..."
  55. exit 3 # Exit error 3: no match found
  56. fi
  57. fi
  58. done
  59. exit 4 # Exit error 4: abnormal error
  60.  
Runtime error #stdin #stdout #stderr 0s 5076KB
stdin
Standard input is empty
stdout
display-find: error! no display was found, check your cables, exiting...
stderr
./prog.sh: line 18: xrandr: command not found