Clock script for Date/Time in FVWM root menu

I have a perl script (thanks to osbourd2 for the help) which I used in Openbox3 to output the date and time to OB’s pipe menu. Now that I have migrated to FVWM, I want to use it with FVWM. Here is the perl script:

[code]#!/usr/bin/perl

use POSIX qw(strftime);

print “” . strftime (($ARGV[0]||"%x %X"), localtime) . “\n”;[/code]

This can be run from the command line without problems. However, my unfamiliarity with FVWM syntax is what is troubling me. I think I should use PipeRead:

[code]AddToMenu MenuFvwmRoot

  • “Clock” Popup MenuFvwmClock

DestroyFunc FuncFvwmClock
AddToFunc FuncFvwmClock

  • I PipeRead 'echo + perl .fvwm/scripts/clock.pl \""%T - %A, %B %e, %Y"\"

DestroyMenu MenuFvwmClock
AddToMenu MenuFvwmClock

  • MissingSubmenuFunction FuncFvwmClock[/code]
    but this doesn’t seem to work. I get an empty entry on the root menu. Could someone please point out my faults, or even a better way to do this (hope I’m not re-inventing the wheel).

[code]time date “+%H:%M:%S”
08:26:30

real 0m0.002s
user 0m0.001s
sys 0m0.002s
time clock.pl “”%T - %A, %B %e, %Y""
08:26:32

real 0m0.027s
user 0m0.015s
sys 0m0.002s[/code]
I guess you should avoid calling perl for that :wink: (even if I’m a great perl fan) It is 10 times longer than ‘date’.

In this case, your clock function for your menu would be much simpler:

[code]AddToMenu MenuFvwmRoot

  • “Clock” Popup MenuFvwmClock

DestroyMenu MenuFvwmClock
AddToMenu MenuFvwmClock

  • DynamicPopupAction Function FuncFvwmClock

DestroyFunc FuncFvwmClock
AddToFunc FuncFvwmClock

  • I DestroyMenu recreate MenuFvwmClock
  • I AddToMenu MenuFvwmClock
  • I PipeRead “date “+%H:%M:%S””[/code]

Thanks pem. I’m getting a little closer, but still not quite there. I tried, as per your suggestion:

+ I PipeRead "date \"+%H:%M:%S\""

which didn’t work. So I altered it and tried it from the command line to make sure it would work:

[code]% echo “+ “date "+%H:%M:%S - %A, %B %e, %Y"””

  • “13:26:16 - Tuesday, February 15, 2005”[/code]
    As can clearly be seen, it should produce a valid menu entry. However, when I save my config and restart FVWM, all that is shown is the “+%H:%M:%S” portion (the time). Am I violating some sacred shell scripting rule if I use spaces within backticks ? I don’t know. I just started diving into shell scripting. When the space is introduced, nothing thereafter shows up in the FVWM menu. Just for kicks, I tried the above without spaces, and lo and behold, it works.

I think you have to escape the spaces (put a "" in front of them).

hth

I tried that as well, but literal backslashes get printed.

I know how much schell scritping can be itchy scratchy when it comes to these backslash thingies. So, here’s the menu with a date (screenshot provided):

+ I PipeRead 'echo \"+ \\"`date "+%H:%M:%S  -  %A, %B %e, %Y\"`\\"\"'

Humm … I was a bit off this morning. :blush:

Excellent work, pem! Thanks.

nice, is there a way can display the clock right on fvwmroot menu instead of in a popup menu?

I got it working by making a small script that would recreate the RootMenu everytime it is popped up.

[code]#~/.fvwm/fvwm_clock.sh
#!/bin/sh
echo “DestroyMenu RootMenu”
echo “AddToMenu RootMenu “date +%R” Title”

And so on and so forth ##[/code]

function ClockRootMenu recreates the menu and opens it

[code]AddToFunc ClockRootMenu

  • I Piperead ‘$HOME/.fvwm/fvwm_clock.sh’
  • I PopupMenu RootMenu[/code]

It’s an ugly hack but it works. Sorry for typos in the code (written in haste) but I hope you get the picture.