Created
December 1, 2019 17:41
-
-
Save mb720/45932d491f4e08b7313cab5f4925436b to your computer and use it in GitHub Desktop.
Script for changing monitor brightness on Linux. Could be mapped to the XF86MonBrightnessUp and XF86MonBrightnessDown keys.
This file contains hidden or 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
#!/usr/bin/env bash | |
# Changes the monitor brightness. | |
# Usage examples: "screen_brightness.sh +500", "screen_brightness 3000" | |
if (( $# >= 1 )); then | |
argument="$1" | |
# Writing to this file changes the monitor brightness. | |
# The parentheses are used to have a wildcard for the | |
# directory containing the brightness file. The directory | |
# could be "intel_backlight" or "acpi_video0", for example | |
brightness_file=(/sys/class/backlight/*/brightness) | |
if [[ $argument = +* ]]; then | |
amount=${argument#*+} | |
current_brightness=$(cat "${brightness_file}") | |
new_brightness=$((current_brightness + amount)) | |
echo $new_brightness > "${brightness_file}" | |
elif [[ $argument = -* ]]; then | |
amount=${argument#*-} | |
current_brightness=$(cat "${brightness_file}") | |
new_brightness=$((current_brightness - amount)) | |
echo $new_brightness > "${brightness_file}" | |
else | |
# If the argument is something else than an integer, this will | |
# yield "write error: Invalid argument" | |
echo "${argument}" > "${brightness_file}" | |
fi | |
else | |
echo "Please pass a single argument. Usage examples: \"screen_brightness.sh +500\", \"screen_brightness 3000\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment