Setting laptop screen brightness at startup

My laptop always starts up at half brightness, and I want it to start up at full brightness.

I wrote a script, “brightness”, which I installed at /usr/local/bin/brightness:

#!/bin/bash
gdbus call --session --dest org.gnome.SettingsDaemon.Power \
      --object-path /org/gnome/SettingsDaemon/Power        \
      --method org.freedesktop.DBus.Properties.Set         \
      org.gnome.SettingsDaemon.Power.Screen Brightness "<int32 $1>"

The script works great from the command line. I can type “brightness 100” to set the display to full brightness, or “brightness 50” to set the display to half brightness.

Now I just need this script to run on startup. I used gnome-session-properties to create a brightness.desktop file in ~/.config/autostart:

[Desktop Entry]
Type=Application
Exec=/usr/local/bin/brightness 100
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en]=Brightness
Name=Brightness
Comment[en]=Sets screen brightness to 100
Comment=Sets screen brightness to 100

However, the brightness stays at half brightness after I log into Gnome. As far as I can tell, the script isn’t running.

Any idea what I am doing wrong, or how I can diagnose this?

You can check if the script is being run at all by making the script creating a file in your HOME directory or something.

Also, I’m not sure if a SystemD unit is a better option here.

I did a bit more debugging. The script is being run, but it fails. It prints to stderr:

Error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SettingsDaemon.Power was not provided by any .service files

The same script works fine when run on the command line. Why is it getting this error when run from ~/.config/autostart?

I guess the service needs some time to start up. I added “sleep 2” at the beginning of the script, and that seemed to be sufficient.

That’s not a particularly satisfying way to do it, but it seems to work.

1 Like

The error means that the service isn’t currently running (read: your autostart script is started before gst-power), and it cannot be autostarted by the D-Bus daemon.

Yeah, I figured it was something like that. It’s too bad there’s not a way to wait until the service is running, but the “sleep 2” seems to do the trick. (At the risk of being completely arbitrary and depending on timing.)

In theory I think gnome-session does allow this, but I’d go for the systemd approach

Though I do wonder why screen brightness isn’t being restored?