I want to run this script on ubuntu 19.04, after booting the OS to restore the previous screen brightness:
echo 50 > /sys/class/backlight/nvidia_0/brightness
How can I run this script so it takes effect at the right moment?
I want to run this script on ubuntu 19.04, after booting the OS to restore the previous screen brightness:
echo 50 > /sys/class/backlight/nvidia_0/brightness
How can I run this script so it takes effect at the right moment?
In Ubuntu 20.04.2 LTS I solved this problem by creating a cron job:
sudo crontab -e
and including this line at the end of the file:
@reboot (sleep 2 ; echo 80 > /sys/class/backlight/nvidia_0/brightness) &
I found that 2 seconds was enough time to override Nvidia's reset timing at boot. You can adjust the brightness level (80) to your own preference.
PS: Just found out that an additional fix is needed: even though the code above fixes brightness at boot, it won't do it when the computer wakes up from sleep/hibernation, Nvidia resets brightness to max again. To fix this, create in addition the following script in a file in the /lib/systemd/system-sleep/ folder:
#!/usr/bin/env bash
action="$1"
case $1 in
post)
echo 80 > /sys/class/backlight/nvidia_0/brightness
;;
esac
Put it in a script eg brightness.sh. , with #!/bin/bash at the top (not sure if this is necessary) make it executable (right click, permissions, executable) , then put that in startup applications - Power Key then type startup, select Startup applications, add button, type (<> are your particular locations)
bash "/home/<username>/<MySctipts>/brightness.sh"
Your system may be setup to automatically restore the last brightness setting already. You can however edit /etc/rc.local
and insert this line before exit 0
at the bottom:
echo 50 > /sys/class/backlight/nvidia_0/brightness
Note you can also use cron@reboot
if rc.local-service
isn't setup in systemd
: