Views:
11,385β
Votes: 14β
β
Solution
Tags:
display
laptop
brightness
xrandr
alienware
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1150409
Title:
Increment Brightness by value using xrandr
ID:
/2019/06/12/Increment-Brightness-by-value-using-xrandr
Created:
June 12, 2019
Edited: January 4, 2021
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Copy bash script below to a file called bright
Then mark it executable with chmod a+x bright
Bash Script
#!/bin/bash
MON="DP-1-1" # Discover monitor name with: xrandr | grep " connected"
STEP=5 # Step Up/Down brightnes by: 5 = ".05", 10 = ".10", etc.
CurrBright=$( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )
CurrBright="${CurrBright##* }" # Get brightness level with decimal place
Left=${CurrBright%%"."*} # Extract left of decimal point
Right=${CurrBright#*"."} # Extract right of decimal point
MathBright="0"
[[ "$Left" != 0 && "$STEP" -lt 10 ]] && STEP=10 # > 1.0, only .1 works
[[ "$Left" != 0 ]] && MathBright="$Left"00 # 1.0 becomes "100"
[[ "${#Right}" -eq 1 ]] && Right="$Right"0 # 0.5 becomes "50"
MathBright=$(( MathBright + Right ))
[[ "$1" == "Up" || "$1" == "+" ]] && MathBright=$(( MathBright + STEP ))
[[ "$1" == "Down" || "$1" == "-" ]] && MathBright=$(( MathBright - STEP ))
[[ "${MathBright:0:1}" == "-" ]] && MathBright=0 # Negative not allowed
[[ "$MathBright" -gt 999 ]] && MathBright=999 # Can't go over 9.99
if [[ "${#MathBright}" -eq 3 ]] ; then
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright="${MathBright:0:1}.${MathBright:1:2}"
else
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright=".${MathBright:0:2}"
fi
xrandr --output "$MON" --brightness "$CurrBright" # Set new brightness
# Display current brightness
printf "Monitor $MON "
echo $( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )
- Change
MON="DP-1-1"
to your monitor name, ieMON="HDMI-1"
- Discover your monitor names using
xrandr | grep " connected"
- Change
STEP=5
to your step value, egSTEP=2
is less noticeable
Call the script with:
bright Up
orbright +
to increase brightness by step valuebright Down
orbright -
to decrease brightness by step valuebright
(with no parameters) to get the current brightness level
Hopefully the bash / shell commands can easily be googled for education but if any questions donβt hesitate to ask :)
8 minutes after posting answer it occurred to me I could have used bc
for floating point math and saved ~10 lines of code and the a lot of time from the 1.5 hours to write it shrugs.