intel-backlight (1081 bytes)
1 #!/bin/bash 2 3 if [[ "$EUID" != 0 ]] 4 then 5 echo "$0 must be run as root" >&2 6 exit 1 7 fi 8 9 [ -z "$1" ] && echo "No argument." && exit 1 10 11 echo "intel-backlight called with: '$1'" >&2 12 13 [[ ! -d /sys/class/backlight/intel_backlight ]] && exit 14 15 current=$(< /sys/class/backlight/intel_backlight/brightness) 16 max=$(< /sys/class/backlight/intel_backlight/max_brightness) 17 min=$((max / 50)) 18 step=$((max / 10)) 19 20 if [[ "$1" =~ ^[0-9]+$ ]]; then 21 if [[ "$1" -eq 0 ]]; then 22 current=0 23 elif [[ "$1" -eq 100 ]]; then 24 current=$max 25 else 26 current=$(( ( ($1 * max) / 100 ) < min ? min : (($1 * max) / 100 ))) 27 fi 28 else 29 case $1 in 30 up) ((current+=step)) ;; 31 down) ((current-=step)) ;; 32 min) current=$min ;; 33 max) current=$max ;; 34 off) current=0 ;; 35 ?) exit ;; 36 esac 37 fi 38 39 40 if (( current < min )) && [[ $1 != off ]] && [[ $1 != 0 ]] 41 then 42 current=$min 43 elif (( current > max )) 44 then 45 current=$max 46 fi 47 48 echo $current >/sys/class/backlight/intel_backlight/brightness