How brightness is controlled on Ubuntu and Linux in general
When it comes to controlling device brightness, typically there are 3 approaches:
xrandr --output <OUTPUT-NAME> --brightness 0.99
which is software-only solution ( not actual hardware ) for GUI ( aka X11 display ). Note that 0.99 is just an example, it can be any floating point number
- DBus service ( which I typically prefer because it doesn't require root level access for regular desktop users)
- Altering virtual files in
/sys
directory, which requires root access
Typically the above applies to monitors, but judging from your question and the script name /etc/acpi/asus-keyboard-backlight.sh
, you are interested in keyboard LEDs. This will determine which of 3 methods we may prefer. xrandr
applies generally to monitors under running GUI, so that is not something we want in this case. DBus and /sys
are more appropriate. If you are after monitor backlight, then WinEunuuchs2Unix's answer should be appropriate.
For keyboard, the specific backlight status files are located typically in /sys/class/led
, with each one named as led0
or for keyboards input0
. Alternative names are also possible. For instance, in a related post the top answer suggests
echo 2 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness
to enable, and
echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness
to disable keyboard backlight for ASUS UX303 LN. This approach would be appropriate if you are using cron jobs, acpi scripts, and any other type of system that may run as root. sudo
of course is not required for such tasks when you run as root already.
If you are going to be controlling the device from within GUI, we may prefer DBus. Of course, it is possible from non GUI session, however it requires figuring out what is the DBus connection we need to use. There is an example on Arch Wiki for controlling keyboard backlight with DBus via Python script. Alternatively, you can consider doing something a long the lines of
qdbus --system org.freedesktop.UPower /org/freedesktop/UPower/KbdBacklight org.freedesktop.UPower.KbdBacklight.SetBrightness 25
where 25 is the value you may want to use. This number may vary by device, so consider trying multiple values and ranges until you find something that works.
See also:
Side notes:
According to the comment by Sato Katsura, keyboard backlight is not standarized under Linux and it depends on whether there exist drivers for each particular hardware in question:
There is no such thing, backlighting is a proprietary extension. Some keyboards do have Linux utilities for changing backlighting, others don't. It's in no way standardised, each vendor does it a different way.