Re: [wmii] Mail notification

From: Adam Gray <>
Date: Thu, 21 Jun 2007 11:48:08 +0100

On 21/06/07, Kai Grossjohann <> wrote:
> I just ran "man mailx" on my Debian box, and got the mail(1) man page.
> It has this option:
> -e, --exist
> Return true if mail exists

Now that's odd because in my mail(1) man page, it says
     -e Don't send empty mails. If the body is empty skip the mail.
So I'm not quite sure what's going on there. Presumably we have
different versions.

Anyway, in the end, it turned out to be a fairly simple problem to
solve. Since I use mbox mail, I could just use the -s bash conditional
operator to see if /var/spool/mail/`whoami` existed with a size
greater than 0. Since I move any read mail to a different mail box
after reading it, this is a good enough indicator of new mail (and
it's very quick to check).

I use a similar looped process to the status script to check for mail
every second, and then write appropriate colours and content to a
section of the bar according to the condition. Very messily written
(my bash scripting skills are not the greatest in the world) but it
does the job. If anyone feels like tidying it up slightly they'd be
welcome to.


# Configuration
newcolors="#ffffff #ff0000 #ff0000"
newmsg="NEW MAIL"
nonewmsg="no new mail"

# Create section on bar
wmiir create /bar/xmail

domailcheck() {
    if [ -s /var/spool/mail/`whoami` ]; then
        echo -n $newcolors | wmiir write /bar/xmail/colors
        echo -n $newmsg | wmiir write /bar/xmail/data
        if [ ! -e newmail.lock ]; then
            aplay $mailnotifysound > /dev/null 2>&1
        touch newmail.lock
        echo -n $nonewcolors | wmiir write /bar/xmail/colors
        echo -n $nonewmsg | wmiir write /bar/xmail/data
        rm -f newmail.lock

while domailcheck
    sleep 1

It uses a lockfile to make sure the alert sound is only played once
(i.e. not every second that there's mail in /var/spool/mail/user)!

Then you can just add a line to wmiirc and ta da, it works. Hope it's
useful to someone (it's definitely useful to me :-))


Adam Gray
"Life + self-doubt = peace"
        -- Jan Buttinger
Received on Thu Jun 21 2007 - 12:48:09 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 16:25:15 UTC