Brightness control with Intel chipsets (ThinkPad etc.)
#!/bin/bash | |
# | |
# Shows and optionally adjusts Intel screen brightness | |
# | |
# Run from command line or bind to shortcut keys | |
# | |
# Usage: brightness [up|down] | |
# | |
# by: Runar Balstad Jensen | |
# url: https://gist.github.com/emning/5d3301a3f3c9420414f7 | |
# ref: http://askubuntu.com/q/428237 | |
# | |
DEV=/sys/class/backlight/intel_backlight | |
STEPS=17 # 17 * 50 = 850, and 851 is the max for my Intel device | |
FUDGE=3 # round up or down if within this much of 0 or MAX | |
sudo_if_needed() | |
{ | |
test $UID = 0 || echo sudo | |
} | |
get_brightness() | |
{ | |
CUR=$(cat $DEV/brightness) | |
MAX=$(cat $DEV/max_brightness) | |
} | |
set_brightness() | |
{ | |
val=$1 | |
if [[ $val -le $FUDGE ]] | |
then | |
val=0 | |
fi | |
if [[ $val -ge $((MAX - FUDGE)) ]] | |
then | |
val=$MAX | |
fi | |
$(sudo_if_needed) tee $DEV/brightness <<< $val > /dev/null | |
} | |
print_brightness() | |
{ | |
echo "$CUR/$MAX ($(((CUR * 100) / MAX)) %)" | |
} | |
if [[ $# -eq 1 ]] | |
then | |
get_brightness | |
case "$1" in | |
up) | |
set_brightness $((CUR + (MAX / STEPS))) | |
;; | |
down) | |
set_brightness $((CUR - (MAX / STEPS))) | |
;; | |
esac | |
fi | |
get_brightness | |
print_brightness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment