Here 2 alternative scripts.
Save it as brightness_change.sh and put it in a folder that is part of your $PATH environment variable.
The usage is simple: brightness_change.sh up / brightness_change.sh down.
You can then assign the script to a keybinding, just take care to specify the full path to the command.
1. DBUS script ( for gnome )
I prefer the Dbus approach because :
- you don't need special permission to change the brightness
- the brightness changes done by script are reflected in the brightness applet
Here the script
#!/bin/bash
function up(){
dbus-send --session --type="method_call" --dest="org.gnome.SettingsDaemon" /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.StepUp
}
function down(){
dbus-send --session --type="method_call" --dest="org.gnome.SettingsDaemon" "/org/gnome/SettingsDaemon/Power" "org.gnome.SettingsDaemon.Power.Screen.StepDown"
}
if [[ $1 = "up" ]]
then
up
elif [[ $1 = "down" ]]
then
down
fi
2. Using the /sys/ files
Using this method requires either you change the permission of the destination file in /sys/ (every boot) either you can had the command to /etc/sudoers to require no passwords
I was not sure how to implement the first way so I have added this line to the /etc/sudoers ( where fra is my user )
fra ALL=(ALL) NOPASSWD:/home/fra/bin/bright_change.sh
Now you can call the command with sudo without you get prompted for password ( it for sure an hole in the security so take care of that )
#!/bin/bash
file="/sys/class/backlight/intel_backlight/brightness"
level=$(cat $file)
inc=100
if [ $level -lt "600" ]
then
inc=50
fi
function up(){
newlevel=$(($level+$inc))
echo $newlevel
}
function down(){
newlevel=$(($level-$inc))
if [ $newlevel -lt "10" ]
then
newlevel=1
elif [ $newlevel -lt "100" ]
then
newlevel=10
fi
echo $newlevel
}
if [[ $1 = "up" ]]
then
newlevel=$(up)
elif [[ $1 = "down" ]]
then
newlevel=$(down)
fi
echo $newlevel
# echo $level
echo $newlevel > $file