Set bindings in i3 to control keyboard backlight

backlighti3keyboard-backlight

For my i3 window-manager settings, I am looking for a command line tool, similar to xbacklight, but to control the brightness of the leds which are in the keyboard.

Basically, I can set up the leds through a command line, but it requires to be root:

# Light off the leds
echo 0 > /sys/class/leds/smc::kbd_backlight/brightness
# Light on the leds (full power)
echo 100 > /sys/class/leds/smc::kbd_backlight/brightness

I know that it is possible because Gnome3 has support for that, but I do not know exactly how they proceed…

For now, my ~/.config/i3/config looks like this:

# screen brightness controls
bindsym XF86MonBrightnessUp exec xbacklight -inc 10
bindsym XF86MonBrightnessDown exec xbacklight -dec 10

# keyboard backlight controls
#TODO
# XF86KbdBrightnessUp
# XF86KbdBrightnessDown

So, is there a tool, similar to xbacklight to do the same than screen brightness with keyboard backlight? It would be even better if this tool would have the control on both (screen and keyboard).

Best Answer

You could write your own pretty easily.

Create two shell scripts containing the echo lines above somewhere in your path (/usr/local is the normal place). Set the permissions 755 owned by root. Then either edit your sudoers file to allow them to be run as root, or use chmod +s to set them SUID.

This sort of thing is considered a security risk, BTW, so make absolutely sure the permissions are set appropriately. You don't want anyone without root permissions to be able to edit the scripts, and you don't want the scripts to use any input.

It would be trivial to add support for a brightness level flag, but unless you're an accomplished shell scripter I'd recommend against it as a bug in your code would be a security hole.

Related Question