Last active
November 17, 2018 16:38
-
-
Save stigok/484f3dfcf1303dd9dbb8daa5cca9d23a to your computer and use it in GitHub Desktop.
Set Intel backlight brightness level Linux bash (Samsung NP300V3A-SE07)
This file contains hidden or 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 | |
# | |
# Set brightness of intel backlight | |
# Usage: | |
# setbrightness | |
# Print current brightness | |
# setbrightness <level> | |
# Set brightness to <level> 1-10 | |
# setbrightness less | |
# Set brightness to current level - 1 | |
# setbrightness more | |
# Set brightness to current level + 1 | |
# | |
# Set screen brightness | |
# Usage: setbrightness more|less|<integer> | |
DIR="/sys/class/backlight/intel_backlight" | |
MAX_VALUE=$( < $DIR/max_brightness ) | |
MAX_STEP=8 | |
STEP_AMOUNT=$(( $MAX_VALUE / $MAX_STEP )) | |
CURRENT_VALUE=$( < $DIR/brightness ) | |
CURRENT_STEP=$(( $CURRENT_VALUE * $MAX_STEP / $MAX_VALUE )) | |
# Set brightness by step value | |
function setstep() { | |
STEP=$1 | |
if [[ $STEP -lt 1 || $STEP -gt $MAX_STEP ]]; then | |
>&2 echo "Invalid step $STEP. Expected number between 1 and $MAX_STEP". | |
exit 1 | |
fi | |
# Set brightness and exit with echo's exit code | |
echo $(( $STEP * $STEP_AMOUNT )) > $DIR/brightness | |
exit $? | |
} | |
if [ -z $1 ]; then | |
echo "Current screen brightness is at step $CURRENT_STEP ($CURRENT_VALUE)" | |
fi | |
echo $CURRENT_STEP $MAX_STEP $CURRENT_VALUE | |
case "$1" in | |
"more") | |
setstep $(( $CURRENT_STEP + 1 )) | |
;; | |
"less") | |
setstep $(( $CURRENT_STEP - 1 )) | |
;; | |
*) | |
if [[ "$1" =~ ^[0-9]{1,2}$ ]]; then | |
setstep $1 | |
fi | |
;; | |
esac |
Yeah, this work also on ThinkPad X220
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My max brightness (
MAX_VALUE
) is 4648, which is divisible by 8, which is why myMAX_STEP
is 8.