<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-cite-prefix">On 10/27/2012 5:06 PM, John Hupp wrote:<br>
</div>
<blockquote cite="mid:508C4CE2.3030101@prpcompany.com" type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<br>
<div class="moz-cite-prefix">On 10/27/2012 3:50 PM, John Hupp
wrote:<br>
</div>
<blockquote cite="mid:508C3B07.6060308@prpcompany.com" type="cite">
<meta content="text/html; charset=UTF-8"
http-equiv="Content-Type">
<br>
<div class="moz-cite-prefix">On 10/27/2012 1:36 AM, Jonathan
Marsden wrote:<br>
</div>
<blockquote cite="mid:508B72D0.7000303@fastmail.fm" type="cite">
<pre wrap="">John,
On 10/26/2012 04:52 PM, John Hupp wrote:
</pre>
<blockquote type="cite">
<pre wrap="">The only problem is that it only posts warning messages to the
wall command, which outputs only to console sessions. ...
</pre>
</blockquote>
<pre wrap="">In my experience, apcupsd is a *lot* more configurable than that -- did
you read its documentation or its scripts before posting?
You can create scripts for each class of event (onbattery, offbattery,
etc.) handled by /etc/apcupsd/apccontrol that do *whatever* you want
them to do -- turn the message into audio and speak it using a speech
synth, if you really want :)
You don't even need to edit /etc/apcupsd/apccontrol to do this, it will
notice that your custom scripts exist, and use them instead of its
internal default actions.
Jonathan
</pre>
</blockquote>
[<font size="-1"><font face="Arial">Newbie sent scurrying to <font
size="-1">d</font>ig into the "Customizing Event Handling"
section o<font size="-1">f the apcupsd manual, and for some
general research on desktop notification<font size="-1">
methods.]<br>
<br>
<font size="-1">OK, <font size="-1">I found out that
notify-send is a comm<font size="-1">on</font>
desktop notification tool, </font></font>and that <font
size="-1">one installs the libnotify-bin</font>
package to get it. I did so.<br>
<br>
</font></font></font></font>I <font size="-1">have now
also created</font> <font size="-1">the</font> shell scrip<font
size="-1">t /<font size="-1">etc/<font size="-1">apcupsd/annoyme.
<font size="-1">I</font>t is owned by root<font size="-1">.
</font>I used the Properties: Permission<font size="-1">s
sheet to give everyone Read & Write permission, and
marked it executable.<br>
<br>
<font size="-1">The contents of <font size="-1">annoyme<font
size="-1">:</font></font></font><br>
<font size="-1"> #!/bin/sh<br>
notify-send -u critical -t 5000 "The computer is
running on battery." "It will shut down shortly.
Please save your work and log off."<br>
exit 0</font><br>
<br>
<font size="-1">Running this script manually pop<font
size="-1">s up a nice warning <font size="-1">on
the desktop for 5 seconds.<br>
<br>
<font size="-1">But <font size="-1">when I pull
the plug for a UPS test, I do not get any
desktop warnings, though <font size="-1">apcupsd
powers down the PC <font size="-1">when</font>
expected. <font size="-1">But</font> if I
log into a console during that time, I see
the </font></font></font></font></font></font></font></font></font></font><font
size="-1"><font face="Arial"><font size="-1"><font size="-1"><font
size="-1"><font size="-1"><font size="-1"><font
size="-1"><font size="-1"><font size="-1"><font
size="-1"><font size="-1"><font size="-1"><font
size="-1"><font face="Arial"><font
size="-1"><font size="-1"><font
size="-1"><font size="-1"><font
size="-1"><font
size="-1"><font
size="-1"><font
size="-1"><font
size="-1"><font
size="-1"><font
size="-1">default
</font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font>onbattery
and annoyme wall messages. As I understand it, <font size="-1">apccontrol</font>
shoul<font size="-1">d run my custom annoyme script before
running its own default annoyme command.</font><br>
<br>
<font size="-1">I have not modified apccontrol.<br>
<br>
<font size="-1">Anyone recognize what the problem is?<br>
<br>
<font size="-1">--------------------------</font><br>
<font size="-1">I could add parameters from my current
configured-for-testing apcupsd.conf:<br>
<br>
UPSCABLE usb<br>
UPSTYPE usb<br>
DEVICE<br>
LOCKFILE /var/lock<br>
SCRIPTDIR /etc/apcupsd<br>
PWRFAILDIR /etc/apcupsd<br>
NOLOGINDIR /etc<br>
<br>
ONBATTERYDELAY 6<br>
BATTERYLEVEL 5<br>
MINUTES 3<br>
TIMEOUT 60<br>
ANNOY 10<br>
ANNOYDELAY 20<br>
NOLOGON always<br>
KILLDELAY 0<br>
<br>
NETSERVER on<br>
NISIP 0.0.0.0<br>
NISPORT 3551<br>
EVENTSFILE /var/log/apcupsd.events<br>
EVENTSFILEMAX 10<br>
<br>
UPSCLASS standalone<br>
UPSMODE disable<br>
<br>
STATTIME 0<br>
STATFILE /var/log/apcupsd.status<br>
LOGSTATS off<br>
DATATIME 0</font></font></font><br>
</blockquote>
<font size="-1"><font face="Arial"><br>
A further test: From <font size="-1">a terminal command line
I ran<font size="-1">:<br>
<br>
<font size="-1"> /etc/apcupsd/apccontrol "annoyme" "" 1
0<br>
<br>
<font size="-1">And my notify-send desktop </font>notification
displayed as envi<font size="-1">sioned.</font></font></font></font></font></font><br>
</blockquote>
<font size="-1"><br>
I found out that the issue is related to the fact that the
apccontrol script called by the apcupsd daemon runs as root, and
DBUS_SESSION_BUS_ADDRESS is not available to root, which means
that the script does not know where the notify-send output should
be displayed.<br>
<br>
There are work-arounds, but I did not understand how to use them
in Lubuntu. The more elaborate solutions use functions that sift
for the current user information and then effectively run the
command of interest (notify-send) as that user.<br>
<br>
The simplest looking solution, if it works, relies on the
procedure for running GUI apps via cronjobs. The reference is to
<a
href="https://help.ubuntu.com/community/CronHowto#GUI%20Applications">https://help.ubuntu.com/community/CronHowto#GUI%20Applications</a>.
But even though the information is there in black-and-white, I
didn't understand how to do it.</font><br>
</body>
</html>