dec-brightness 760 B

1234567891011121314151617181920212223
  1. #!/bin/sh
  2. # script to decrease the display brightness by $1%
  3. [ -z "$1" ] && echo "Error: please give percent as argument" && exit 1
  4. #xbacklight -dec "$1"
  5. #exit
  6. # get brightness device
  7. device=$(brightnessctl -l | grep "class 'backlight'" | tail -n +2 | awk '{print $2}' | tr -d "'")
  8. if brightnessctl -l | grep "class 'backlight'" | grep -q "^Device 'intel_backlight'\|^Device 'acpi_video"; then
  9. device="$(brightnessctl -l | grep "class 'backlight'" | awk '{print $2}' | tr -d "'")"
  10. fi
  11. # get brightness percentage
  12. brightness=$(brightnessctl -d "${device}" | grep Current | awk -F '[)(]' "{print \$2 - $1}")
  13. # correct negative values to 0
  14. echo $brightness | grep -q '^-' && brightness=0
  15. # set brightness
  16. brightnessctl -d "${device}" set "$brightness"%