1

while I was trying to fix a problem I faced this file:

/etc/acpi/asus-keyboard-backlight.sh

which has code for handling the increasing and decreasing of brightness.
so, I need to know where is the similar file which ubuntu 18 really depends on to handle increase and decrease requests.
thanks in advance!

  • 1
    This may help. I don't think there is a shell script for this, you may have to look at the source code of the linux kernel or a desktop environment to get a clue what happens when you change screen brightness via system settings or a keyboard shortcut. The systemd service mentioned in the linked wiki could also give you some hints. – danzel Apr 09 '19 at 09:16

3 Answers3

1

I am not clear about your question. However, looking at the topic of your question I can propose the following commands to try and change the screen brightness. Follow the link for the script.

If you need to set your brightness to 50%

select the primary display

DEV=$(xrandr -q | grep connected | grep primary | cut -d' ' -f1)

adjust the brightness

xrandr --output "$DEV" --brightness "0.5"

Script: [https://github.com/kusal-rabbie/dont-lift/blob/master/bl][1]

  • 1
    Note that xrandr is software-only solution and requires running X11 server, which means it re-draws the screen to appear dim. It doesn't decrease physical brightness of a device. – Sergiy Kolodyazhnyy Apr 09 '19 at 23:24
1

There are dozens of ways to do this: How to change LCD brightness from command line (or via script)?

I think though if you want to know how Ubuntu does it then this answer within the link is probably closest:

Using DBus with Gnome

Increase brightness

gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepUp

Decrease brightness

gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.gnome.SettingsDaemon.Power.Screen.StepDown

Automatic Adjustments

For myself I use eyesome which gets sunrise / sunset times each day from the internet. Then it adjusts screen brightness and gamma for both the laptop and two external HDMI TVs. The adjustment is gradual as a transition period of 1 to 2 hours is used at sunrise and sunset. I wrote the program so I'm biased :)

0

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.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497