Sort of solved - Udev rule to run script on AC connect or disconnect

Hello!

Since in gnome-shell 3.24.2 the extension that once dimmed the brightness of my screen on AC disconnect and brightned it on AC connect does no longer work as gnome yet another time removed something from gdbus ... I am trying to make a udev rule now....

What I got so far:
dimonbat.rules
SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/etc/udev/dimscreen.sh"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/etc/udev/undimscreen.sh"

These two lines are just copied from the arc-wiki

The scripts contain as following
dimscreen.sh

#!/bin/bash
# dim screen when on bat (not on AC)
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 30>'

undimscreen.sh

#!/bin/bash
# brighten up to 100 when on AC
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 100>'

Problem now is, that each script does exactly what it should when called from the terminal but not when I unplug the AC adapter.

UPDATE: it seems that the gdbus call only works for the user that is loged into the graphical session... when I run it as my user it work (the command and so does the script) but when run as root I get:
Fehler beim Verbinden: Fehler beim Erzeugen der Befehlszeile »dbus-launch --autolaunch=d174a9311d8d41368d8551e33500d6b4 --binary-syntax --close-stderr«: Der Kindprozess wurde mit Status 1 beendet
Which translates (roughly I guess) to
Error on connect: Error on creating the command-line »dbus-launch --autolaunch=d174a9311d8d41368d8551e33500d6b4 --binary-syntax --close-stderr«: The childprocess terminated with status 1

Giving it a slight bump - maybe that helps :innocent:

I might be able to pull something from my butt, but I don't understand the premise here.

It sounds like you are on a laptop that is running off battery. And when you plug your laptop in, your screen gets brighter, and when you unplug it the screen gets dimmer.

If that is the case, the power settings already have this feature. You don't need an extension or a script.

If I am wrong, please correct me so I can better assist you.

That is my desired behaviour - at the moment gnome-shell and the laptop just ignore what power source is used; The screen stays at what ever brighness I set it.

I would want it to go to 30 or 25% even when it switches to BAT and 100% again when AC is reconnected.

I had the extension dim-on-battery which did that through dconf but gnome 3.24.2 removed the "flag" or option so the extension which is unmaintained does not work anymore.

That is why I went googling and came up with the udev sniplet and the two lines for setting brightness with gdbus.

I fail at makind udev work - I am not sure if its not triggered or the scripts can not be run.

Hi @Tjj226_Angel I have been looking for assistance at the manjaro formum as well ( the distro I am using) and we got so far that the gdconf command just will not work if not called from the logged in users session. So either F2 (run) or in a terminal emulator it will work, but neither with sudo -u user or with udev calling it as that user - its realy bad what gnome-devs did again.

Yeah, I sent a message to the gnome people.

This used to be a features, so IDK what the hell is going on.

1 Like

Hope your more lucky in getting a reply than this one - no rep in dev circles - more the power noob XD

I guess it's to improve simplicity and uniformity or so - at least that's their #1 excuse.

It is "kinda" fixed - I was able to fix the gnome-shell extension "dim-on-battery-extension" (https://github.com/Th3Z0ne/gnome-shell-dim-on-battery-extension) that way the gdbus call is happening in user context and it works.

Thanks a lot @Tjj226_Angel for helping! It is almost embarissing how easy the fix was - but I had to kinda learn gdbus and java enough first XD

I was working on my own extension too.

I was actually trying to circumvent gdbus all together. I am trying find a way where the program looks at the actual power icon at the top menu. If the icon changes to charging or fully charged, the screen will get brighter.

That way the extension should work for several new gnome releases.

1 Like

Cool approach - I am realy curious about that one =) as I have the feeling gdbus will be changed soon again - as always :rage:

Hope that there is a non gdbus way of changing the brightness so that gnome-shell also recognises it (the slider not staying at 100 or so)

Well we could always try the script approach.

When icon changes, spam a certain key combination to lower brightness.

Its far less pretty of a solution, but it would be a lot more solid.

1 Like

Like in looking at the pixels that are drawn or the command that causes the icon file to be changed?

that is one approach I am thinking of.

Obviously it would not work for pretty much anyone other than a select few people because screen resolution, themes, and all sorts of other crap becomes and issue.

But it would solve the problem for you. I am trying to make something really niche to help out the few people who are stuck with this issue until the gnome team can build something like this into gnome for good.

Yeah that was my first thought as i do not use the default adawait theme.

Untill the next change in gdbus (which I hope they just don't do) its solved - the extension that I was trying to work around I fixed ^^ and placed a pull request so hopefully the maintainer will accept it - so everyone can use it again and have their screens dim.

that is realy the most puzzeling - I mean laptops are tbh the most used devices I encounter amongst linux/gnome users - and they (gnome devs) just give a flying fuck about such "standard features" even windows has ootb

Oh I know. I am doing this now just as an exercise because I can apply this to some other issues other people are having.

And it could be used as a back up when the bus changes again.

1 Like

Cool - just wanted to make sure your not wasting your time because of a probable misunderstanding or my lack of communicating it sufficiently =)

Yeah - backup is realy good to have - feel free to shoot me a msg when you need a guinea pig :wink:

lol. Here ya go. The search thing should still work, but I want to incorporate some newer search utilities in it. The OSX menu still works (hopefully) and the widget menu doesn't work, but I only really need to make a bug fix. However that being said, it is basically broken. The calendar doesn't work for what ever reason, and I want to add in some media controls and stuff like that.

The ultimate goal is to turn gnome into OSX.

1 Like