Skip to content

Instantly share code, notes, and snippets.

@mrf345
Last active February 9, 2019 12:44
Show Gist options
  • Save mrf345/46800a9d9439890f0bd50c2777847b4a to your computer and use it in GitHub Desktop.
Save mrf345/46800a9d9439890f0bd50c2777847b4a to your computer and use it in GitHub Desktop.
control backlight brightness on linux window manager
#!/bin/bash
config_file=/sys/class/backlight/intel_backlight/brightness
brightness=$(cat $config_file)
max_brightness=100000
brightness_measure=$(( max_brightness / 10 ))
function get_percentage() {
percent=$(( $brightness * 100 / $max_brightness ))
echo Brightness: $percent/100
}
case "$1" in
1)
if [ $brightness -lt $max_brightness ]
then
brightness=$(( $brightness + $brightness_measure ))
sudo tee $config_file <<< "$brightness" > /dev/null 2>&1
fi
get_percentage
;;
0)
if [ $brightness -gt $brightness_measure ]
then
brightness=$(( $brightness - $brightness_measure ))
sudo tee $config_file <<< "$brightness" > /dev/null 2>&1
fi
get_percentage
;;
*)
echo Error: wrong input
echo $0 1 to increase, 0 to decrease
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment