Skip to content

Instantly share code, notes, and snippets.

@mschewe
Last active December 12, 2015 06:39
Show Gist options
  • Save mschewe/4730852 to your computer and use it in GitHub Desktop.
Save mschewe/4730852 to your computer and use it in GitHub Desktop.
Helper script to set the screen brightness on a Lenovo T530
#!/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