[Lubuntu] Notifications to all users in X sessions?
John Hupp
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
the way?
------------
And here is an example of a script that addresses one known user:
#!/bin/sh
init_notify() {
user=`whoami`
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
export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
done
}
notify() {
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
init_notify
fi
title=$1
text=$2
timeout=$3
if [ -z "$title" ]; then
return
fi
if [ -z "$text" ]; then
text=$title
fi
if [ -z "$timeout" ]; then
timeout=5000
fi
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
notification.
# Don't forget to write the correct username in the "init_notify()"
function.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/lubuntu-users/attachments/20121031/9f540dff/attachment.html>
More information about the Lubuntu-users
mailing list