Skip to content

Instantly share code, notes, and snippets.

@alpiua
Forked from andreafortuna/brightness.sh
Created August 28, 2020 00:34
Show Gist options
  • Save alpiua/65c48910d99f0281ee2af2bf9ae87ca1 to your computer and use it in GitHub Desktop.
Save alpiua/65c48910d99f0281ee2af2bf9ae87ca1 to your computer and use it in GitHub Desktop.
Simple script to modify screen brightness
#!/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