Hello,
I have written script to set-up brightness of backlight in XFCE (it will probably works with any linux distribution and X). It is only editing number in /sys/class/backlight/acpi_video0/brightness. This script works good in command line, it will decrease/increase brightness by 1 degree, but I have different problem with that script.
When I make shortcuts in XFCE (Applications-> preferences-> keyboard -> keyboard shortcuts tab) and associate commands bright -p / bright -m with keys for changing brightness on my laptop it works properly too, but bad things is, that on one press of key, it decrease or increase brightness by 2 degrees. In other words, this script is executed twice on one press of key. How to execute it only once on one press of key?
PS: I know, in XFCE exist plugin for regulating backlight brightness, but I didn't found, how to drive it from command line (for keyboard) and it forgets last set value, so after reboot, backlight is back on maximum.
My script looks like that (If it help):
Code:
#!/bin/bash
# Script for changing backlight brightness in /sys/class/backlight/acpi_video0/brightness
# can take values 0-15, in real (my notebook) works only values 2-15
#IMPORTANT: you must have writing rights to /sys/.../brightness (I must solute it with visudo or something like that...)
#IMPORTANT: for proper work after reboot must exist directory .bright in your home directory and file last_bright in .bright directory
#reads content of brightness and save it into variable
BRIGHT=$(cat /sys/class/backlight/acpi_video0/brightness)
while getopts "pmlh" optname
do
case "$optname" in
"p")
#Add more brightness
#BRIGHT++
BRIGHT=$(($BRIGHT+1))
#protect mechanism (BRIGHT must be lower or equal to 15)
if (($BRIGHT>15))
then
BRIGHT=$((15))
fi
;;
"m")
#decrease brightness
#BRIGHT--
BRIGHT=$(($BRIGHT-1))
#protect mechanism (BRIGHT must be bigger or equal to 2)
if (($BRIGHT<2))
then
BRIGHT=$((2))
fi
;;
"l")
echo "Loading last value of brightness."
#Load last value, saved in file last_bright
BRIGHT=$(cat $HOME/.bright/last_bright)
echo "Poslední hodnota bright je $BRIGHT"
;;
"h")
echo "Help: "
echo "-p Increase brightness"
echo "-m Decrease brightness"
echo "-l Load last brightness value"
echo "-h This help"
echo "Programmed by: ElectricZero"
;;
"?")
echo "Unkonwn argument, try bright -h for help"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
done
echo "Brightness set on $BRIGHT"
#Save variable BRIGHT into file brightness
echo $BRIGHT > /sys/class/backlight/acpi_video0/brightness
#Save variable BRIGHT into file last_bright
echo $BRIGHT > $HOME/.bright/last_bright