Here's the corrected version of your brightness adjustment script with explanations:
#!/bin/sh
# Define brightness path
BrPath='/sys/class/backlight/intel_backlight/'
# Get current/max brightness values
BrCur=$(cat "${BrPath}brightness")
BrMax=$(cat "${BrPath}max_brightness")
# Calculate 1% minimum brightness (rounded up)
BrMin=$(( (BrMax + 99) / 100 ))
# Create the brightness slider window
yad --scale \
--min-value "$BrMin" \
--max-value "$BrMax" \
--value "$BrCur" \
--print-partial \
--title "Set Brightness - radky's Dpup Stretch 7.5 (RC3)" \
--width 300 \
--fixed-pos \
--sticky \
--on-top \
--escape-ok \
--button=OK \
--hide-value | while read -r BrNew; do
echo "$BrNew" > "${BrPath}brightness"
done
Key fixes and improvements:
-
Title Fix:
- Fixed the title string by using double quotes to handle the apostrophe in "radky's"
-
Brightness Calculation:
- Added parentheses for clarity in the BrMin calculation formula
- Added comments for better code understanding
-
Yad Options:
- Removed invalid
--mouse option
- Changed
--fixed to --fixed-pos for proper positioning
- Added
-r flag to read for better input handling
- Improved option ordering for readability
-
Quoting:
- Added quotes around variable expansions to prevent word splitting
- Used
$() instead of backticks for command substitution
-
Code Structure:
- Added spacing for better readability
- Improved variable naming consistency
- Added comments for clarity
To use this script:
- Make it executable:
chmod +x brightness.sh
- Run with root privileges:
sudo ./brightness.sh
Note: You might need to adjust the backlight path (intel_backlight) if your system uses a different driver (e.g., acpi_video0). Check available backlight interfaces with ls /sys/class/backlight/.
If you encounter permission issues, consider:
- Adding the script to sudoers with NOPASSWD
- Using udev rules to grant permissions
- Creating a systemd service for root execution