Last active
December 12, 2015 06:39
-
-
Save mschewe/4730852 to your computer and use it in GitHub Desktop.
Helper script to set the screen brightness on a Lenovo T530
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=/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness | |
CURRENT_VALUE=$(cat $BRIGHTNESS) | |
value=$(echo $1 | grep -E -o '[[:digit:]]+') | |
if [[ $# -ne 1 ]] | |
then | |
echo "$0 +VALUE | -VALUE | VALUE" | |
exit | |
fi | |
if [[ -z $value ]] | |
then | |
echo "please supply a number" | |
exit | |
fi | |
if [[ $1 == -* ]] | |
then | |
let new_value="$CURRENT_VALUE - $value" | |
if [[ $new_value -le 0 ]] | |
then | |
new_value=0 | |
fi | |
echo $new_value | sudo tee $BRIGHTNESS | |
elif [[ $1 == +* ]] | |
then | |
let new_value="$CURRENT_VALUE + $value" | |
if [[ $new_value -ge 100 ]] | |
then | |
new_value=100 | |
fi | |
echo $new_value | sudo tee $BRIGHTNESS | |
else | |
echo $1 | sudo tee $BRIGHTNESS | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment