Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# /etc/acpi/thinkpadbrightness.sh
#
# Script to change brightness of a ThinkPad t540p
#
# put this to /etc/acpi/events/thinkpad-brightness-down
#
# event=video/brightnessdown BRTDN 00000087 00000000
# action=/etc/acpi/thinkpadbrightness.sh down
#
# put this to /etc/acpi/events/thinkpad-brightness-up
#
# event=video/brightnessup BRTUP 00000086 00000000
# action=/etc/acpi/thinkpadbrightness.sh up
MIN_BRIGHTNESS=100
CHANGES=20
MAX_BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/max_brightness)
BRIGHTNESS=$(cat /sys/class/backlight/intel_backlight/brightness)
BRIGHTNESS_CHANGE=$(( $MAX_BRIGHTNESS / $CHANGES ))
DOWN_BRIGHTNESS=$(( $BRIGHTNESS - $BRIGHTNESS_CHANGE ))
UP_BRIGHTNESS=$(( $BRIGHTNESS + $BRIGHTNESS_CHANGE ))
if [ "x$1" = "xdown" ]; then
if [ "$DOWN_BRIGHTNESS" -lt "$MIN_BRIGHTNESS" ]; then
DOWN_BRIGHTNESS=$MIN_BRIGHTNESS
fi
echo $DOWN_BRIGHTNESS > /sys/class/backlight/intel_backlight/brightness
elif [ "x$1" = "xup" ]; then
if [ "$UP_BRIGHTNESS" -gt "$MAX_BRIGHTNESS" ]; then
UP_BRIGHTNESS=$MAX_BRIGHTNESS
fi
echo $UP_BRIGHTNESS > /sys/class/backlight/intel_backlight/brightness
else
echo >&2 Unknown argument $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment