Last active
July 29, 2022 22:57
-
-
Save pcting/d36ab5074b37ff3c219b248c190fa7aa to your computer and use it in GitHub Desktop.
backlight script for Lenovo ThinkPad P15s Gen 2i
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 | |
# Example: increae brightness by 15% | |
# backlight.sh inc 15 | |
CURRENT_BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/brightness) | |
MAX_BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/max_brightness) | |
ONE_PERCENT_FACTOR=$(( MAX_BRIGHTNESS / 100 )) | |
BRIGHTNESS_STEP=$2 | |
case "$1" in | |
-inc ) | |
NEW_BRIGHTNESS=$(( CURRENT_BRIGHTNESS + (BRIGHTNESS_STEP * ONE_PERCENT_FACTOR) )) | |
;; | |
-dec ) | |
NEW_BRIGHTNESS=$(( CURRENT_BRIGHTNESS - (BRIGHTNESS_STEP * ONE_PERCENT_FACTOR) )) | |
;; | |
*) | |
echo $CURRENT_BRIGHTNESS ' / ' $MAX_BRIGHTNESS | |
exit 0 | |
;; | |
esac | |
NEW_BRIGHTNESS=$((NEW_BRIGHTNESS>MAX_BRIGHTNESS ? MAX_BRIGHTNESS : NEW_BRIGHTNESS)) | |
NEW_BRIGHTNESS=$((NEW_BRIGHTNESS<0 ? 0 : NEW_BRIGHTNESS)) | |
# need permissions to write: | |
# $ cat /etc/sudoers.d/intel_backlight | |
# ALL ALL = (ALL) NOPASSWD: /usr/bin/tee /sys/class/backlight/intel_backlight/brightness | |
echo $NEW_BRIGHTNESS | sudo tee /sys/class/backlight/intel_backlight/brightness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment