Created
January 14, 2024 08:27
-
-
Save stjernstrom/8ce17473f46d5a8f18deca2b49455192 to your computer and use it in GitHub Desktop.
Adjust brightness with brightnessctl in dynamic increments
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 | |
brightness_breakpoint=10 | |
brightness_cmd="/usr/bin/brightnessctl -c backlight" | |
brightness_data=$($brightness_cmd) | |
cur_brightness=$(echo $brightness_data | grep -Po "(?<=Current brightness: )[0-9]+") | |
max_brightness=$(echo $brightness_data | grep -Po "(?<=Max brightness: )[0-9]+") | |
brightness_percent=$(bc <<< "scale=2; ($cur_brightness / $max_brightness) * 100") | |
percent_int=${brightness_percent%.*} | |
if [ $1 = '--dec' ] | |
then | |
[[ $percent_int -le $brightness_breakpoint ]] && adjust_amount=1 || adjust_amount=5 | |
$brightness_cmd -q s $adjust_amount%- | |
else | |
[[ $percent_int -ge $brightness_breakpoint ]] && adjust_amount=5 || adjust_amount=1 | |
$brightness_cmd -q s +$adjust_amount% | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment