Running a script before or once login screen appears
There are two ways to approach this:
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
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
/etc/lightdm/lightdm.conf
file is empty. Is it strange or normal? – sirajalam049 Feb 28 '17 at 07:12