Advertisement
juls0730

brightness.sh

Sep 11th, 2021
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Define environment variables
  4. MAX_BRIGHTNESS=100
  5. MIN_BRIGHTNESS=20
  6. BRIGHTNESS_STEPS=10
  7. curBright=$(ybacklight -get | rev | cut -c5- | rev)
  8.  
  9. function brightUp() {
  10. if [ "$curBright" = "$MAX_BRIGHTNESS" ]; then
  11. echo "Current Brightness: " $curBright
  12. echo "Brightness is already at maximum"
  13. elif [ $((curBright + BRIGHTNESS_STEPS)) -ge $MAX_BRIGHTNESS ]; then
  14. ybacklight -set 100
  15. echo "Brightness has been set to 100"
  16. elif [ $((curBright + BRIGHTNESS_STEPS)) > $MAX_BRIGHTNESS ]; then
  17. ybacklight -inc 10
  18. echo "Brightness has been incremented"
  19. fi
  20. }
  21.  
  22. function brightDown() {
  23. if [ "$curBright" = "$MIN_BRIGHTNESS" ]; then
  24. echo "Current Brightness: " $curBright
  25. echo "Brightness is already at minimum"
  26. elif [ $((curBright - BRIGHTNESS_STEPS)) -ge $MIN_BRIGHTNESS ]; then
  27. ybacklight -set 20
  28. echo "Brightness has been set to 20"
  29. elif [ $((curBright - BRIGHTNESS_STEPS)) > $MIN_BRIGHTNESS ]; then
  30. ybacklight -dec 10
  31. echo "Brightness has been decremented"
  32. fi
  33. }
  34.  
  35. while [[ "$1" = --* ]]; do
  36. unset arg
  37. if [[ "$1" = *=* ]]; then
  38. arg="${1//=*/}"
  39. shift
  40. else
  41. arg="$1"
  42. shift
  43. fi
  44.  
  45. case "$arg" in
  46. --brightness-up)
  47. brightUp
  48. ;;
  49. --brightness-down)
  50. brightDown
  51. ;;
  52. --get-brightness)
  53. getCurBright
  54. ;;
  55. *)
  56. echo "Unrecognised option: $arg" >&2
  57. exit 1
  58. ;;
  59. esac
  60. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement