Last active
November 5, 2018 17:58
-
-
Save apiraino/7eed0c49ea7f672c62d602c7de82844f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# set -x | |
# /usr/lib/gnome-settings-daemon/gsd-backlight-helper | |
#Application Options: | |
# --set-brightness Set the current brightness | |
# --get-brightness Get the current brightness | |
# --get-max-brightness Get the number of brightness levels supported | |
GNOME_BL_HELPER="/usr/lib/gnome-settings-daemon/gsd-backlight-helper" | |
DELTA=54 | |
brightness () { | |
MAX_VAL=$( $GNOME_BL_HELPER --get-max-brightness ) | |
MIN_VAL=0 | |
CURR_VAL=$( $GNOME_BL_HELPER --get-brightness ) | |
SIGN=$1 | |
case "$SIGN" in | |
"+") | |
DIFF=$( echo "$MAX_VAL-$CURR_VAL" | bc -l ) | |
if [ "$DIFF" -gt $DELTA ]; then | |
NEW_VAL=$( echo "$CURR_VAL $SIGN $DELTA" | bc -l ) | |
else | |
NEW_VAL=$( echo "$CURR_VAL $SIGN $DIFF" | bc -l ) | |
fi | |
echo "Setting new brightness: $NEW_VAL" | |
pkexec $GNOME_BL_HELPER --set-brightness $NEW_VAL | |
;; | |
"-") | |
DIFF=$( echo "$CURR_VAL $SIGN $DELTA" | bc -l ) | |
if [ "$DIFF" -gt $DELTA ]; then | |
NEW_VAL=$( echo "$CURR_VAL $SIGN $DELTA" | bc -l ) | |
else | |
NEW_VAL=$MIN_VAL | |
fi | |
echo "Setting new brightness: $NEW_VAL" | |
pkexec $GNOME_BL_HELPER --set-brightness $NEW_VAL | |
;; | |
*) | |
echo "Current brightness: $CURR_VAL" | |
esac | |
} | |
case "$1" in | |
inc) | |
brightness "+" | |
;; | |
dec) | |
brightness "-" | |
;; | |
*) | |
brightness show | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment