Educating yourself does not mean that you were stupid in the first place; it means that you are intelligent enough to know that there is plenty left to 'learn'. -Melanie Joy

Monday, 24 November 2014

Change the screen brightness using bash script - xrandr

November 24, 2014 Posted by Dinesh , , ,

In my Ubuntu 14.0 (Dell Inspiron), brightness controls were not working at all. So I started searching for other alternatives to sets the brightness.

finally I found this xrandr.
it is great tool to set the brightness and even to rotate the screen.


--brightness flag can be used to set the brightness (best values: 0 - 1)
--brightness flag cab be used to rotate the screen (possible options : normal, left, right) 

Usage:
          ./brightness_control.sh +      # Increase the brightness by 0.05
          ./brightness_control.sh  -       # Decrease the brightness by 0.05
          ./brightness_control.sh 1       # Set brightness to 1
 
 

#!/bin/bash
# brightness_control.sh
_help()
{
echo
echo "Usage:"
echo "$0 [No args] Sets/resets brightness to default (1.0)."
echo "$0 + Increments brightness by 0.5."
echo "$0 - Decrements brightness by 0.5."
echo "$0 Number Sets brightness to N (useful range .7 - 1.2)."
}
bright=$(xrandr --verbose | grep rightness | awk '{ print $2 }')
DISP_NAME=$(xrandr | grep LV | awk '{print $1}')
INCR=0.05
case $1 in
+)bright=$(echo "scale=2; $bright + $INCR" | bc);;
-)bright=$(echo "scale=2; $bright - $INCR" | bc);;
*)_help && exit ;;
esac
xrandr --output "$DISP_NAME" --brightness "$bright" # See xrandr manpage.
echo "Current brightness = $bright"
exit
view raw xrandr.sh hosted with ❤ by GitHub