Advertisement
starbeamrainbowlabs

Custom brightness controller

Sep 17th, 2015
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. increment=10
  3. backlight_prefix=/sys/class/backlight/intel_backlight/
  4.  
  5. echo $1
  6. if [[ "$1" = "decrease" ]]; then
  7.     echo decreasing
  8.     increment=$(expr -${increment})
  9. fi
  10.  
  11. cur_brightness=$(cat ${backlight_prefix}brightness)
  12. max_brightness=$(cat ${backlight_prefix}max_brightness)
  13.  
  14. new_brightness=$(expr ${cur_brightness} + ${increment})
  15.  
  16. # Permissions changes on brightness:
  17. ## change group to sbrl
  18. ## add g+w
  19. # Old command:
  20. #gksudo -- bash -c "echo ${new_brightness} >${backlight_prefix}brightness"
  21. echo ${new_brightness} >${backlight_prefix}brightness
  22.  
  23. ####################
  24. ### Notification ###
  25. ####################
  26. ### uncomment the following line to disable the notification
  27. #exit
  28. # Calculate the percentage
  29. new_percent=$(echo "(${new_brightness} / ${max_brightness}) * 100" | bc -l)
  30. new_percent=$(printf "%.1f" "${new_percent}")
  31.  
  32. echo new_percent: $new_percent
  33.  
  34.  
  35. max_bar_length=100
  36. bar_length=$(echo "(${new_percent} / 100) * ${max_bar_length}" | bc -l)
  37. bar_length=$(printf "%.0f" "${bar_length}")
  38.  
  39. n_bar=$(head -c $bar_length < /dev/zero | tr '\0' '=')
  40.  
  41. # Kill the previous notification
  42. killall notify-osd
  43. notify-send "Brightness: ${new_percent}%" "${n_bar} (${new_brightness})"
  44. #notify-send "Brightness" "${new_percent}%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement