lapdots/i3blocks/brightness
2024-10-02 14:29:45 -04:00

22 lines
744 B
Bash
Executable file

#!/bin/bash
# File paths
BRIGHTNESS_FILE="/sys/class/backlight/intel_backlight/brightness"
MAX_BRIGHTNESS_FILE="/sys/class/backlight/intel_backlight/max_brightness"
# Read the current brightness and maximum brightness values
current_brightness=$(cat "$BRIGHTNESS_FILE")
max_brightness=$(cat "$MAX_BRIGHTNESS_FILE")
# Check if max_brightness is greater than 0 to avoid division by zero
if [ "$max_brightness" -le 0 ]; then
echo "Error: Max brightness is not a positive number."
exit 1
fi
# Calculate the brightness percentage and round to the nearest whole number
brightness_percentage=$(echo "scale=0; ($current_brightness * 100 / $max_brightness)" | bc)
# Output the brightness percentage
echo "Backlight: ${brightness_percentage}%"