You are not logged in.
Pages: 1
Hello. I'm trying to make udev send me notifications concerning current status of battery, but I'm stumbled across some difficulties.
Here is an example of my udev rule:
SUBSYSTEM=="power_supply", ATTR{status}=="Not charging", RUN+="/usr/bin/sudo -u username -E notify-send -a 'udev' 'Battery is charged' 'Plug off the charger'"I tried to run the exact same command as root and it works as it supposed, but when I plug in charger nothing happens. I checked status attribute and it has value "Not charging". What am I doing wrong?
Offline
Preserving the environment won't work, because the relevant bits aren't there to be preserved.
https://wiki.archlinux.org/title/Udev#T … _udev_rule
Online
Preserving the environment won't work, because the relevant bits aren't there to be preserved.
Ok, but my dbus session file is not in the /run/user/1000/. It is somewhere in /tmp and always has random names, I suppose. How can I handle this?
Offline
Why? How do you start the session?
Don't use "ly" nor "dbus-launch".
Otherwise, import the environment from a session process, see https://gist.github.com/AladW/de1c5676d93d05a5a0e1 for a **SAMPLE**.
Online
Why? How do you start the session?
I don't know. Wiki says that it starts automatically. I haven't changed anything. How am I supposed to start session?
Offline
I don't know. Wiki says that it starts automatically.
What? What wiki? How did you install archlinux?
In case this is a slan barrier: "how do you log into your desktop environment?"
Online
What? What wiki?
This wiki: https://wiki.archlinux.org/title/D-Bus
How did you install archlinux?
Just ordinary manual installation. It was before archinstall.
how do you log into your desktop environment?
startx
Offline
startx
Post your xinitrc and see the last link below.
Online
Post your xinitrc
$ cat .xinitrc
# init keyring
eval $(/usr/bin/gnome-keyring-daemon --start --components=gpg,pkcs11,secrets,ssh)
# export keyring
export GNOME_KEYRING_CONTROL GNOME_KEYRING_PID GPG_AGENT_INFO SSH_AUTH_SOCK
exec dbus-launch bspwmAhh, now I see, but even now I don't know how to start dbus properly. I will check your link.
Offline
Post your xinitrc and see the last link below.
So, please, tell me how to start dbus, which will be connected with bspwm and its session file will be in /run/user/1000/ directory?
Offline
You're not supposed to start dbus (I asked how you start the session - "startx" - the session *bus* is actually started automatically by systemd/logind)
In particular not using dbus-launch (so get rid of that)
What you need to do is to import the relevant environment into your X11 session, the relevant bit is the 2nd blue note in the wiki link.
Online
What you need to do is to import the relevant environment into your X11 session, the relevant bit is the 2nd blue note in the wiki link.
Sorry, I just don't understand where to look? What variables I need to import? And how to do it? Just
export DBUS_SESSION_BUS_ADDRESSin .xinitrc? Maybe then I should export all variables in .xinitrc? Help me to understand this, please.
Offline
Note: At the very least, ensure that the last if block in /etc/X11/xinit/xinitrc is present in your ~/.xinitrc file to ensure that the scripts in /etc/X11/xinit/xinitrc.d are sourced.
It's not about *exporting* anything, but *importing*…
Online
It's not about *exporting* anything, but *importing*…
Thank you. Now variables are ok, but I still don't get any notifications. Here is my rule:
SUBSYSTEM=="power_supply", ATTR{status}=="Not charging", RUN+="/usr/bin/su username -c /home/username/Scripts/charged.sh"And here charged.sh:
#!/usr/bin/bash
export XAUTHORITY=/home/username/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
/usr/bin/notify-send -a 'udev' 'Battery is charged' 'Plug off the charger'When this line as root everything works, but not when I plug in the charger.
What is wrong now?
Offline
I added a line:
/usr/bin/touch /home/username/Scripts/filebefore notify-send and it doesn't create any files too.
Offline
Where did you get that udev rule from? udevadm monitor?
Also, did you reload the udev rules?
And just to be sure: you did replace "username" w/ your actual username?
Online
Where did you get that udev rule from? udevadm monitor?
It is from /etc/udev/rules.d. I manually tried to trigger rules and they work. May be it is because udev don't trigger power_supply rules when I plug off or plug in charger. I read somewhere that udev trigger rules when battery capacity level changes, but is there another reasons it trigger these rules?
Offline
It is from /etc/udev/rules.d
No, I meant "how did you come up w/ that rule"
Online
No, I meant "how did you come up w/ that rule"
I don't know. I just thought that udev check attributes in every rule and if all of them match, then it triggers it. So, it is just logic.
Offline
So, it is just logic.
Ex falso…
Check for the actual events w/ udevadm monitor and apply them accordingly.
Online
Pages: 1