Last active
July 25, 2020 20:30
-
-
Save vmsh0/3c901821ffa9d0630ae4a8da12ecc7f4 to your computer and use it in GitHub Desktop.
Script to quickly change the brightness value on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
low_brightness_clamp=200 # you should probably change this depending on the brightness range of your driver | |
dev=$1 | |
prm=$2 | |
sys="/sys/class/backlight/$dev" | |
if [ ! -e "$sys" ]; then | |
>&2 echo "device not found" | |
exit 1 | |
fi | |
[ -n "$prm" ] && [ "$prm" -eq "$prm" ] 2>/dev/null | |
if [ $? -ne 0 ]; then | |
>&2 echo "invalid input" | |
exit 2 | |
fi | |
max_brightness=$(cat "$sys/max_brightness") | |
brightness=$(cat "$sys/brightness") | |
new_brightness=$(($brightness + $prm)) | |
if [ $new_brightness -gt $max_brightness ]; then | |
new_brightness=$max_brightness | |
fi | |
if [ $new_brightness -lt $low_brightness_clamp ]; then | |
new_brightness=$low_brightness_clamp | |
fi | |
echo $new_brightness > "$sys/brightness" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness" | |
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'd probably want to put the script in /usr/bin/brightness, and the udev rules in /etc/udev/rules.d/50-backlight.rules.
Then you should add your user to the video group with
usermod -aG [username]
Restart your PC to have the udev rules applied, then use as e.g.:
(you can find out what to put in the place of "intel_backlight" by looking in /sys/class/backlight/)