Skip to content

Instantly share code, notes, and snippets.

@briceburg
Created May 17, 2014 00:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briceburg/81d2c8d95a7cf4f61c0a to your computer and use it in GitHub Desktop.
Save briceburg/81d2c8d95a7cf4f61c0a to your computer and use it in GitHub Desktop.
simple linux shell script to adjust backlight - useful for xmonad
#!/bin/bash
# backlight brightness controls. use freely
# and adjust sysfs directory if not on toshiba
# $author Brice Burgess @iceburg
sysfs="/sys/class/backlight/toshiba"
max=`cat ${sysfs}/max_brightness`
level=`cat ${sysfs}/brightness`
usage()
{
script=${0##*/}
echo
echo "Invalid usage of ${script}!"
echo " $1"
echo "----------------"
echo "$script up : increases brightness"
echo "$script down : decreases brightness"
echo "$script set # : sets brightness to # (integer)"
echo "----------------"
echo
exit 1
}
set_brightness()
{
level=$1
if [ $level -lt 1 ] ; then
level=1
elif [ $level -gt $max ] ; then
level=$max
fi
echo $level > $sysfs/brightness
}
case "$1" in
up)
let "level+=1"
set_brightness $level
;;
down)
let "level-=1"
set_brightness $level
;;
set)
if [[ ! $2 =~ ^[[:digit:]]+$ ]]; then
usage "second argument must be an integer"
fi
set_brightness $2
;;
*)
usage "invalid argument"
esac
@ckrzen
Copy link

ckrzen commented Oct 17, 2016

Thank you very much for this script!

I have modified it and posted my use of it for others to benefit, here:

https://ubuntuforums.org/showthread.php?t=2340223

Much appreciated,

Chris Rainey
Tulsa, OK
USA

@gorlapraveen
Copy link

gorlapraveen commented Apr 1, 2018

My modified version is added on git and further updates are at gitlab.com .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment