You are not logged in.
I have a udev rule where I use environment variables (e.g. $USER):
SUBSYSTEM=="power_supply", \
ATTR{status}=="Discharging", \
ATTR{capacity}=="[0-5]", \
ENV{DBUS_SESSION_BUS_ADDRESS}="unix:path=/run/user/$UID/bus", \
RUN+="/usr/bin/su $USER -c '/usr/bin/notify-send --urgency=critical \"Low Battery\" \"$attr{capacity}% remaining\"'"
Currently, I have the actual values hardcoded, but I would like to reference the environment variables. Does anyone know how to achieve this?
Last edited by hakunamatata (2018-06-22 09:26:00)
Offline
You put them in a script.
Offline
udev rules are executed as root, these won't resolve to your user correctly.
Online
The batify AUR package uses the xpub script to extract the information about the currently active user. xpub or some similar script is the only way you can use user specific information in udev.
https://aur.archlinux.org/packages/xpub/
https://aur.archlinux.org/packages/batify/
Last edited by progandy (2018-06-20 21:29:23)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
# grab user details from the environment
arr=(
$(strings /proc/$pids/environ |\
awk -F'=' '/^USER/{user=$2};\
/^DISPLAY/{display=$2}; /^DBUS/{bus=$3}\
END {print user"\n"display"\nunix:path="bus}')
)
user="${arr[0]}"
dply="${arr[1]}"
dbus="${arr[2]}"
Offline
I was hoping for a "cleaner" solution. I think I will stick with the hardcoded solution for now. Thank you all anyway.
Offline