2

I have been trying to get my laptop's screen brightness to default to a low setting, and for my keyboard light to be off when I start my computer.

I have these two commands that work when I execute them at the command line:

xbacklight -set 7
echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness

I put them in my /etc/rc.local file, like so:

#!/bin/sh -e
# ...
# By default this script does nothing.
echo 0 | tee /sys/class/leds/asus::kbd_backlight/brightness
xbacklight -set 7
exit 0

However, neither command executes. (I was told that the sudo was not needed in the second command when placed in /etc/rc.local)

There was another question asking the same thing about rc.local, but I tried to also include my commands using the Startup Applications GUI interface. That also did not work, so I think the problem might go beyond just the rc.local file. Other default startup commands in the list seem to start, so far as I can tell.

Why am I unable to get any custom command line to execute when I startup?


New: After some experimentation, it seems like the commands I put in /etc/rc.local might be getting executed before the login screen. So, my login screen has the screen appropriately dimmed. However, then when I login, my screen goes to maximum brightness. So it seems like perhaps there is some other setting that is being applied when I log in, or that /etc/rc.local only applies for the login screen itself and has no bearing on what happens to a user when logged in.

So, how do I resolve this so that the brightness and keyboard light settings I want apply to the user login session, not just to the login screen?

Questioner
  • 6,959

5 Answers5

4

xbacklight solution

1) Create an executable script file e.g. /home/YOU/.bin/lower-brightness like this:

#!/bin/sh
xbacklight -set 7 &

2) Create a .desktop file e.g. /home/YOU/.config/autostart/lower-brightness.desktop like this:

[Desktop Entry]
Type=Application
Exec=/home/YOU/.bin/lower-brightness
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Lower Screen Brightness
Comment=Screen brightness is set to 7 at startup
Icon=display
Sadi
  • 11,074
1

To have the display settings as you want you can add this line in /etc/rc.local

echo 7 > /sys/class/backlight/intel_backlight/brightness

Then it can keep your brightness as 7.

hope that helps a bit.

Raja G
  • 105,327
  • 107
  • 262
  • 331
1

I'm sure, my solution should help you if you use ubuntu with lightdm.

I was searching for turning on NumPad on my laptop when it starts and in lightdm documentation I found this:

# display-setup-script = Script to run when starting a greeter session (runs as root)
# greeter-setup-script = Script to run when starting a greeter (runs as root)
# session-setup-script = Script to run when starting a user session (runs as root)
# session-cleanup-script = Script to run when quitting a user session (runs as root)

And that is solution. You need to create file in /usr/bin/, say /usr/bin/backlight and write commands there.

#!/bin/bash
xbacklight -set 7
echo 0 | sudo tee /sys/class/leds/asus::kbd_backlight/brightness
exit 0

(Also xbacklight doesn't work for me. echo 7 > /sys/class/backlight/intel_backlight/brightness does the stuff). Than make sure you add execute permission for this file with chmod a+x /usr/bin/backlight.

Than you need to edit /etc/lightdm/lightdm.conf and write for example this line:

session-setup-script=/usr/bin/backlight

And that's it. Now restart you PC.

Viktor K
  • 1,139
1

Create your own init script to adjust the brightness levels.

echo '#!/bin/sh 
sleep 60
echo 0 | tee /sys/class/leds/asus::kbd_backlight/brightness
xbacklight -set 7
exit 0' > /tmp/myinit
sudo mv /tmp/myinit /etc/init.d/myinit
sudo chmod +x /etc/init.d/myinit
sudo update-rc.d myinit defaults  

Adjust the sleep value to your suit.

totti
  • 6,908
  • 4
  • 40
  • 48
0

I wonder why no one has suggested using update-rc.d. I would not put the script into /etc/rc.local manually. I would recommend this way to make programs run at startup:

sudo cp lower-brightness.sh /etc/init.d/
sudo chmod +x /etc/init.d/lower-brightness.sh 
sudo update-rc.d lower-brightness.sh defaults 

This will make sure the script is linked to appropriate run levels.