Last active
April 20, 2023 17:40
-
-
Save andreafortuna/6eea255e1846c894d46c4b7d8b813878 to your computer and use it in GitHub Desktop.
Simple script to modify screen 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
#!/bin/bash | |
# Simple script to modify screen brightness | |
# USAGE: | |
# brightness.sh +20 (Increase brightness by 20%) | |
basedir="/sys/class/backlight/" | |
# get the backlight handler | |
handler=$basedir$(ls $basedir)"/" | |
# current brightness | |
old_brightness=$(cat $handler"brightness") | |
# max brightness | |
max_brightness=$(cat $handler"max_brightness") | |
# current % | |
old_brightness_p=$(( 100 * $old_brightness / $max_brightness )) | |
# new % | |
new_brightness_p=$(($old_brightness_p $1)) | |
# new brightness value | |
new_brightness=$(( $max_brightness * $new_brightness_p / 100 )) | |
# set the new brightness value | |
sudo chmod 666 $handler"brightness" | |
sudo echo $new_brightness > $handler"brightness" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment