Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.