Created
March 22, 2025 21:44
-
-
Save lvnilesh/67d10ecc72d13a6d6145fa1b91ebfb35 to your computer and use it in GitHub Desktop.
brightness control stepper script
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/bash | |
# Get current brightness level | |
current_brightness=$(xrandr --verbose | grep -m 1 -i brightness | awk '{print $2}') | |
# Define step size for brightness change | |
step=0.1 | |
# Adjust brightness based on argument | |
if [ "$1" = "up" ]; then | |
new_brightness=$(echo "$current_brightness + $step" | bc) | |
elif [ "$1" = "down" ]; then | |
new_brightness=$(echo "$current_brightness - $step" | bc) | |
else | |
echo "Usage: $0 up|down" | |
exit 1 | |
fi | |
# Ensure brightness stays within 0.1 to 1.0 range | |
if (( $(echo "$new_brightness < 0.1" | bc -l) )); then | |
new_brightness=0.1 | |
elif (( $(echo "$new_brightness > 1.0" | bc -l) )); then | |
new_brightness=1.0 | |
fi | |
# Apply new brightness value | |
xrandr --output DP-4 --brightness "$new_brightness" | |
xrandr --output DP-0 --brightness "$new_brightness" | |
# Optional: Display new brightness | |
echo "Brightness set to: $new_brightness" | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment