[Lubuntu] Notifications to all users in X sessions?
lubuntu at prpcompany.com
Wed Oct 31 19:19:57 UTC 2012
I am re-approaching a question I first began chewing on in the thread
"[Lubuntu] Capture "wall" messages for display on desktop?"
For a Lubuntu LTSP network powered by a UPS, during a power outage I
want to notify all users in all X sessions with a popup message saying
that the system is running on battery and about to be shut down. My
starting point is the the UPS management daemon runs a control script
which will call my custom script named "annoyme," and will run that
script as root.
I have been trying to do this with notify-send, but there is the
inherent problem that when notify-send is run as root, there is no
DBUS_SESSION_BUS_ADDRESS variable, and notify-send relies on that value
to direct its output to the proper session.
There are some scripts that solve the problem for a given user name (see
below), but I want to address all users in general. Somewhere along the
line, I thought I saw such a script in passing, but now I can't find it.
I imagine that there is already a developed method for handling a job
like that, using either notify-send or something else. Can anyone point
And here is an example of a script that addresses one known user:
pids=`pgrep -u $user nautilus`
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
if [ -z "$title" ]; then
if [ -z "$text" ]; then
if [ -z "$timeout" ]; then
notify-send "$title" "$text" -t $timeout
# Just copy&paste these two functions into your script and just type
'notify "title" "text" 5000' in your script where you want to send a
# Don't forget to write the correct username in the "init_notify()"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lubuntu-users