1
0
Fork 0

Laptop screen brightness control script

This commit is contained in:
Gregory Eremin 2023-02-14 10:59:45 +01:00
parent e54a1e7869
commit ba1030783b
1 changed files with 40 additions and 0 deletions

40
bin/laptop-screen-brightness Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# Keys: XF86MonBrightnessUp, XF86MonBrightnessDown
class=intel_backlight
dir=/sys/class/backlight/$class
cur=$(cat $dir/brightness)
max=$(cat $dir/max_brightness)
step=$(("$2" + 0))
cur_pct=$((100 * $cur / $max))
case "$1" in
"up")
echo "up $2%"
target_pct=$(($cur_pct + $2))
;;
"down")
echo "down $2%"
target_pct=$(($cur_pct - $2))
;;
*)
echo "Backlight at $cur/$max ($cur_pct%)"
exit 0
esac
if [ "$target_pct" -lt "0" ]; then
target_pct=0
fi
if [ "$target_pct" -gt "100" ]; then
target_pct=100
fi
target_val=$(($max * $target_pct / 100))
echo "Backlight at $cur/$max ($cur_pct%)"
echo "Target $target_val ($target_pct%)"
echo "Dest $dir/brightness"
echo $target_val > $dir/brightness