Last active
January 31, 2022 23:03
-
-
Save luixal/12f8ea750e4b01acb1aad1b012b8d1b4 to your computer and use it in GitHub Desktop.
Gnome Brightness Control Hack for fn keys
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: Change all monitors brightness in software. | |
# by hackerb9, 2019 | |
# Examples: brightness 75; brightness -5; brightness +10 | |
# Usage: | |
# brightess [n] [+n] [-n] | |
# n An integer from 0 to 100 specifies a brightness level. | |
# +n Increase brightness by n. | |
# -n Decrease brightness by n. | |
# No argument shows current brightness level. | |
b=$(xrandr --current --verbose | grep Brightness) | |
b=${b#*: } # Remove "Brightness: " | |
b=${b#0.} # 0.30 --> 30 | |
[[ $b == "1.0" ]] && b="100" | |
case $1 in | |
+*|-*) | |
b=$((b $1)) # b=b+10, b=b-10 | |
;; | |
[0-9]*) | |
b=$1 # b=75 | |
;; | |
*) | |
echo $b; exit | |
;; | |
esac | |
[[ $b -lt 0 ]] && b=0 | |
[[ $b -gt 100 ]] && b=100 | |
if [[ $b -eq 100 ]]; then | |
b=1.0 | |
else | |
b=0.$b | |
fi | |
outputs=$(xrandr --current | awk '$2 == "connected" {print $1}') | |
for o in $outputs; do | |
xrandr --output $o --brightness $b | |
done |
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: Change all monitors brightness in software. | |
# by luixal (2022) based on script from hackerb9 (2019) | |
# Examples: brightness 0.75; brightness -0.5; brightness +0.1 | |
# Usage: | |
# brightess [n] [+n] [-n] | |
# n An integer from 0 to 100 specifies a brightness level. | |
# +n Increase brightness by n. | |
# -n Decrease brightness by n. | |
# No argument shows current brightness level. | |
# get current brightness value: | |
b=$(dconf read /org/gnome/shell/extensions/soft-brightness/current-brightness) | |
# set new value according to parameter's syntax/value: | |
case $1 in | |
+*|-*) | |
# b=$((b $1)) # b=b+0.1, b=b-0.1 | |
b=`echo $b $1 | bc` | |
;; | |
[0-9]*) | |
b=$1 # b=0.75 | |
;; | |
*) | |
echo $b; exit | |
;; | |
esac | |
# set min value: | |
[[ $(bc -l <<< "$b < 0") -eq 1 ]] && b=0 | |
# set max value: | |
[[ $(bc -l <<< "$b > 1") -eq 1 ]] && b=1 | |
# set brightness value: | |
dconf write /org/gnome/shell/extensions/soft-brightness/current-brightness $b | |
# echo current (just set) value: | |
echo $b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added simpler version that uses
dconf
instead ofxrandr
(seems to be the gnome way). Also, doesn't make unit conversion but takes brightness values between 0 and 1 (ej: instead of 10 you should pass 0.1).