Ubuntu – Can you help me write a script to set a new default brightness for the screen/keyboard after login

backlightbrightnesspower-managementscreenscripts

On my Macbook Pro Ubuntu alsways boots with…

  • keyboard brightness at maximum illumination
  • screen brightness at maximum illumination

…both which I need almost never during normal usage.

Question

Instead of directly manipulating configuration files, I'm thinking
of a solution that would work like a script and set both brightness
settings to a lower default. How might this be accomplished?

Unfortunately, I have no experience in scripting and would be glad if you can help me out here.


I've figured out what needs to be done to change both the screen brightness and the keyboard backlight. Can you help be to make this a script that is automatically run at login?

Change Keyboard backlight

echo 130 | sudo tee -a /sys/class/leds/smc::kbd_backlight/brightness

…where 255 is the maximum brightness and 0 is the lowest brightness.

Change screen brightness

echo 42311 | sudo tee /sys/class/backlight/gmux_backlight/brightness 

…where 4126 is the lowest brightness and 82311 the hightest.


I've noticed a another problem.. If I run echo 42311 | sudo tee /sys/class/backlight/gmux_backlight/brightness right after login, but then use the brightness buttons. The screen brightness settings first reset to maximum – and then the change get's applied.
This is seems messed up…

Best Answer

You can have root run the brightness commands upon reboot, by adding those commands to /etc/rc.local (gksudo gedit /etc/rc.local), so that it looks like:

#!/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.

echo 130 >> /sys/class/leds/smc::kbd_backlight/brightness
echo 42311 > /sys/class/backlight/gmux_backlight/brightness

exit 0

See also Brightness is reset to Maximum on every Restart

Related Question