FvwmCheckMail

I’m not really sure how this FvwmScript thing works, even though I’ve read the manual pages, and several of the Scripts that come with fvwm.

What I’m trying to achieve, is a window which would be Swallowed into FvwmButtons. All it has to do is to get the output of a command, and display that in the window. No widgets whatsoever needed (I think).
The command I’m trying to use in it, is ‘newmail’, which outputs like so:

# newmail -di ~/Mail/received
You don't have new mail in /home/mikko/Mail/received.

Heres my script:

WindowTitle     {FvwmCheckMail}
WindowSize      64 64
Colorset        0

Init
  Begin
    If (RemainderOfDiv (GetTime) 10)==0 Then
      GetOutPut {Exec exec newmail -di ~/Mail/received}
      End

So … I don’t get any kind of output, but looking at the output of ‘ps’, FvwmScript seems to be running. I also tried with ‘GetOutPut’ changed to ‘Do’ (which was taken straight form the man-page)
Any help greatly appreciated.

you need at least one widget, since a widget is “anything that can be displayed”.

I’ve not tried GetOutPut but you could use the string it returns to set the title on a DrawItem. That said, I’ve not been able to make ItemDraw (or anything else for that matter) accept multi line text, so this only works well for single line outpit

Another possinility is to ExecSwallow an xterm and display that using a small font. Then you could do something like this:

[code]WindowTitle {FvwmScript-Mailcheck}
WindowSize 100 100

Widget 1
Property
Size 100 100
Position 0 0
Type SwallowExec
Value 0
Title {mini-mail-check}
SwallowExec {exec xterm -bg black -fg purple -T mini-mail-check -fn
5x7 -e watch -n 600 killmail -L&}
End
[/code]

That works on my machine. The “killmail -L” command is my home grown spam killer. With a -L flag it non-destructively lists mail on my ISP server. Using “watch -n 600” reruns the command every 10 mins - useful for a dockapp.

Or there are always the scrollbar widgets to play with. I’ve not got up to them yet.

Cheers and thanks for the info.
I tried to bang my head against it for a while, but ended up searching mailing list archives for a wheel-already-discovered.
So I found Uwe Pross’s approach using a program called ‘lsmbox’.
Ok, so first I edited Uwes FvwmScript -file exhausting myself.
Then I moved on to using ‘sed’ on his scipt to suit me. That made me frustrated.
Then I moved on to making a shell-script which in turn would create the configuration I wanted. Ending up with this:

#!/bin/sh
MAILSDIR=$1
COUNT=0
[ -z "$MAILSDIR" ] && { echo "Usage: $(basename $0) <MAILDIR>"; exit 1; }
MAILFILES=$(for i in $(ls -ld $MAILSDIR/*|\
awk '!/.log/&&!/.gz/&&!/^d/{print $9}'); do basename $i; done)
echo "WindowTitle {FvwmCheckMail}"
echo "WindowSize 60 192"
echo "WindowPosition 0 0"
echo "Colorset 0"
echo "Font \"xft:monospace:size=8\""
echo ""
echo "Init"
echo "  Begin"
for i in $MAILFILES; do
    echo "    Set \$${i}_mail=0"
    done
for i in $MAILFILES; do
    COUNT=$(($COUNT+1))
    echo "    Set \$${i}_mail={ $(echo $i | awk '{print toupper(substr($1,1,6))}'): } (GetOutput {lsmbox -t -o -n $MAILSDIR/$i | grep Summary} 1 2)"
    echo "ChangeTitle $COUNT \$${i}_mail"
    done
echo "End"
echo ""
echo "PeriodicTasks"
echo "  Begin"
echo "    If (RemainderOfDiv (GetTime) 10)==0 Then"
echo "      Begin"
COUNT=0
for i in $MAILFILES; do
    COUNT=$(($COUNT+1))
    echo "        Set \$${i}_mail=(GetOutput {lsmbox -t -o -n $MAILSDIR/$i | grep Summary} 1 2)"
    echo "        Set \$${i}_title={ $(echo $i | awk '{print toupper(substr($1,1,6))}'): } \$${i}_mail"
    echo "        ChangeTitle $COUNT \$${i}_title"
    echo "        If \$${i}_mail>0 Then"
    echo "          ChangeForeColor $COUNT {red}"
    echo "        Else"
    echo "          ChangeForeColor $COUNT {black}"
    echo ""
    done
echo "  End"
echo "End"
COUNT=0
PCOUNT=0
for i in $MAILFILES; do
    COUNT=$(($COUNT+1))
    PCOUNT=$(($PCOUNT+15))
    echo "Widget $COUNT"
    echo "Property"
    echo "  Size 60 15"
    echo "  Position 0 $PCOUNT"
    echo "  Flags NoReliefString Left"
    echo "  Type ItemDraw"
    echo "  Title { init ... }"
    echo "Main"
    echo "  Case message of"
    echo "    SingleClic :"
    echo "    Begin"
    echo "      Do {Exec xterm -e mail -f '$MAILSDIR/$i' &}"
    echo "    End"
    echo "End"
    echo ""
    done

(It takes the full path to a folder containing mbox files as only argument (I use procmail) the mbox file name gets truncated to 6 letters on screen if longer than that)
This produces code which would seem to be consistent with the original Uwes configuration file. However I get nothing printed on the screen. Help? Please? :evil:

[EDIT] Now it sort of works. One last problem I’m having with this, is that I don’t get the last mbox in the list displayed.

[EDIT2] I’d like to add an idea to use alternatively the shortest mailbox name as the number of letters the longer mailbox names get truncated to.
You can add the following code to the beginning of the above script, and replace from it the the awk commands to awk -v MIN=$MINWIDTH, and change the “6” to MIN

MINWIDTH=$(echo "$MAILFILES"|awk '{print length($1)}'|awk '
NR == 1 {m=$1 ; p=$1}
$1 >= m {m = $1}
$1 <= p {p = $1}
END { print p + 1 }')

(Yes, it takes the longest too, but doesn’t do anything with that yet.)

I ran the script with /tmp as an arg and got:

[code]WindowTitle {FvwmCheckMail}
WindowSize 64 192
WindowPosition -2000 -2000
Colorset 0
Font “xft:monospace:size=8”

Init
Begin
End

PeriodicTasks
Begin
If (RemainderOfDiv (GetTime) 10)==0 Then
Begin
End
End
[/code]

WindowPosition -2000 -2000
is going to create your window way way offscreen. Deliberately I expect, possible so it can be moved on at a keypress and back off to carry on in background mode. Also, the script still doesn’t do anything, but that may just be because I don’t have any mailboxes in /tmp :slight_smile:

Try something like this:

[code]WindowTitle {FvwmScript-Mailcheck}
WindowSize 400 400
Font 5x7

Init
Begin
Set $cmd={newmail -di ~/Mail/received}
Set $word=(GetOutput $cmd 1 -1);
ChangeTitle 1 $word

    Set $last = (GetTime)

End

PeriodicTasks
Begin
Set $now = (GetTime)
If $now > $last Then
Begin
Set $last = $now
If (RemainderOfDiv (GetTime) 10)==0 Then
Begin
Set $word=(GetOutput $cmd 2 -1);
ChangeTitle 1 $word
End
End
End

Widget 1
Property
Size 400 400
Position 0 0
Type ItemDraw
End[/code]

That should take the first line of output from your newmail command (can’t test it - I don’t have it) and display it in a window.

There’s a couple of other FvwmScript pitfalls. Unlike most of FVWM it is case sensitive. So GetOutput is ok, but GetOutPut is a syntax error. The second one is that error messages get output by Fvwm; so if you don’t have a log, or don’t know to look, you’ll never see them.

That’s interesting. I suppose one would need Gnu awk for that to work, then.
Just out of curiosity; what OS did you ran it in?

Well, the script is supposed to run like

/path/to/the/script /location/of/mailboxes > /some/file/to/output.it

Ahh! Thanks! I’ll give it a whirl first thing in the morning :smiley:

Aha! The case sensitivity could very well be the pitfall in my script. Have to look at it with new eyes.

I run Gentoo Linux - GNU awk installed.

I thing the problem with the shell script may lie with the ls command. If I run ls -ldf /tmp/* I get

[code]/tmp/Lioc09d.tmp /tmp/vm.12333
/tmp/Lioc09e.tmp /tmp/vm.13370
/tmp/Lioc09f.tmp /tmp/vm.15310
/tmp/Lioc0a1.tmp /tmp/vm.16651
/tmp/Lioc0a3.tmp /tmp/vm.16762
/tmp/Lioc0a4.tmp /tmp/vm.16855
/tmp/Lioc0a5.tmp /tmp/vm.18758
/tmp/Lioc0a6.tmp /tmp/vm.18760
/tmp/Lioc0b0.tmp /tmp/vm.19071
/tmp/Lioc0b1.tmp /tmp/vm.31962
/tmp/Lioc0b4.tmp /tmp/vm.8181

etc…

[/code]
Awk separates its input into fields based upon white space. so from the above output it would find a $1 and a $2, but $9 would be empty - which is what we’re seeing. Of course a directory with uniformly short names would generate more columns, but file ordering in ls -f seems an odd thing for a script to rely upon.

Oh nice. BSD ls and GNU ls don’t work alike then.
In BSD, the directories are listed recursively, hence the -d.
-f had no particular purpose in the script, other than the output is not sorted (which I thought would have speeded up it a bit) So it seems removing the -f makes it work in linux, too. -l is needed to not include the directories with awk.

[EDIT] I’ve made the change to the above script. I hope the removing of ‘f’ -switch is enough to make it work in Linux.