2

Whenever I boot, the brightness is set to full. I read this and make changes so that it do not reset every time I boot into my laptop.

But before this, I tried to change brightness before login, but brightness buttons only work when I log in. So after my problem of Brightness is reset to Maximum on every Restart is solved, I just want to know any way to change the brightness just after OS start, that is before login.

1 Answers1

2

Running a script before or once login screen appears

There are two ways to approach this:

  1. Place command or call to script in /etc/rc.local. For instance

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    # path to my script. Note the & at the end, it's important
    /home/serg/bin/brightness_set.sh &
    exit 0
    
  2. The login screen is actually known as desktop manager, and Ubuntu in particular uses lightdm desktop manager. Its configuration file /etc/lightdm/lightdm.conf can take greeter-setup-script= parameter to execute something before login screen actually shows up. For instance, you could do:

    [Seat:*]
    greeter-setup-script=/opt/set_brightness.py
    

    NOTE: Older versions of the header [SeatDefaults] is deprecated now, use [Seat:*]. Also, if you have never edited /etc/lightdm/lightdm.conf it will be blank - that's the normal behavior since 14.04 Ubuntu version.

Controlling the brightness:

Setting brightness will have to be done by writing to brightness file in /sys/class/backlight/<NAME> directory. There are couple different <NAME> versions than can appear, for example mine is /sys/class/backlight/intel_backlight , so you will need to figure out the name your own computer uses or alternatively use /sys/class/backlight/*/brightness. There is also max_brightness file in the same location, which you can use as 100% value to calculate brightness to set. Both files accept integer value.

Common way to write into that file is via echo 123 | sudo tee /sys/class/backlight/*/brightness from command line. If you are running a script via /etc/rc.local or via greeter-setup-script= parameter mentioned above, sudo is not necessary, as both method run scripts with root privillege ( which is also important to remember for security reasons, so ensure your script is accessible only to your user or root only ) .

There are also alternatives to writing into /sys , but not all of them are good. In my experience xbacklight doesn't work for Ubuntu users and xrandr --output SCREEN_NAME --brightness INT is only a software solution (i.e., it doesn't actually decrease power of the screen, only makes screen turn darker color).

Additional resources

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