Last active
June 5, 2017 14:32
-
-
Save meatballhat/bbef50cd582ab2eeb71a50db5341e3ed to your computer and use it in GitHub Desktop.
ACPID event handler for video/brightness(up|down)
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/sh | |
set -o errexit | |
DEVICE=/sys/class/backlight/intel_backlight | |
BRIGHTNESS_FILE="${DEVICE}/brightness" | |
MAX_BRIGHTNESS="$(< $DEVICE/max_brightness)" | |
STEP=$((MAX_BRIGHTNESS / 20)) | |
read_brightness() { | |
cat "${BRIGHTNESS_FILE}" | |
} | |
write_brightness() { | |
local value="${1}" | |
if [[ $value -gt $MAX_BRIGHTNESS ]]; then | |
value="${MAX_BRIGHTNESS}" | |
fi | |
echo "setting brightness of ${DEVICE} to ${value}" | |
echo "${value}" >"${BRIGHTNESS_FILE}" | |
} | |
main() { | |
case $1 in | |
+) write_brightness $(($(read_brightness) + STEP)) ;; | |
-) write_brightness $(($(read_brightness) - STEP)) ;; | |
esac | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment