2009-04-21 Update: LXTerminal and fbpanel have a clock built in which does the job nicely.
The basic idea is to call up a terminal whose title is the current date and time. Think of it this way.. I don’t need to have a clock staring me in the face all the time, so I just need to bring it up occasionally and then dismiss it, and so I don’t need to worry about fancy things like it staying updated.
This was for Blackbox. See also bbtime
Intro ∞
This is my way of pulling up a clock. I never need to look at a clock for more than a few seconds, so a permanent clock is a waste of time. Why would I need to see a graphical clock, when text displays the information I need? So I combined these ideas by using a dirty trick on a terminal’s title.
The old bbkeys:
KeyToGrab(C), WithModifier(Control+Mod1), WithAction(ExecCommand), DoThis(rxvt -name "`date +%a\ %b\ %d,%l\:%M\ %p`" -geometry 24x0+0+0) ^ ^ ^ ^ ^ 1 2 3 4 5
The new bbkeys:
[Execute] (Mod1-Control-C) {rxvt -name "`date +%a\ %b\ %d,%l\:%M\ %p`" -geometry 24x0+0+0}
1) I used a hotkey in bbkeys. The above is an excerpt from my .bbkeysrc file.
2) I used rxvt as the terminal I open. Another choice could be used, although that may change things.
There are ways to not open a terminal window, but to instead paint a generic window with some other program. I chose a terminal window because it then gives me some interesting flexibility. I thought up this trick back on my p2 266 when I had resource and speed concerns of running yet another application, this trick was as fast or faster than any other method I experimented with.
3) One of the available switches to rxvt is to set the name of its title. This is one method to call the title. A commandline can also do it:
echo -e "\e]2;This is the new window title\a"
And this gives two other ways to set the title. Most terminal program can be told to run a certain command when they start. So I could put the above echo as that command, or I could tell the terminal to run a script, within which has that echo string.
Instead of using a -name switch like this, I could use -e <command> switch to run a command. This would let me run a script. I bring this up because it would be an interesting thing to have this clock come up and close down automatically after 10 seconds or something.
4) This is the date string which I use as my clock. Basically what I’m doing is executing the date program. Because bbkeys is really just executing this command on the commandline, I can use backticks to surround a string to execute an arbitrary program and pass its results back to the string. In this case, the results of the date program are being given to the -name tag (item 3)
5) rxvt allows me to set the geometry of the window by way of the -geometry switch its startup string.
One could also manipulate the window title with resize -s <rows> <colums>:
resize -s 1 24
The unfortunate thing with this is it limits the user to 1 row.
resize -s 1 24 works, but resize -s 0 24 gives full-height. I want 0 height so I can only show the title bar.
Quirks ∞
-
my prompt automagically overwrites the title of an rxvt window, destroying this trick. I don’t know how to fix this. =(
- 2009-04-21 update: I could force rxvt to read an alternate config file, maybe a nonexistant one, to have no title auto-updating.
- I have experimented with
-exec while a=a; do echo ok; donebut I dunno how to get that to work either. - I can see in
/etc/bashrcthat the prompt is set. - I need to make the prompt non-interactive to fix this.
-
I can no longer use a multi-word title. I don’t understand why.
-
There is still some part of the input area shown, and so I use -fg and -bg switches with “SteelBlue”, the colour of my title bar, to try to hide things. I don’t know if this is an rxvt or a Blackbox thing.
Evolution ∞
-
This could be redone such that a small script just opens up a title bar. In theory it would be even lighter and simpler than this solution. Maybe I’ll persue doing this in Ruby somehow.
- I don’t want to rely on extra “parts” though. =(
For Blackbox and bbkeys I used to do this:
KeyToGrab(C), WithModifier(Control+Mod1), WithAction(ExecCommand), DoThis(rxvt -name "`date +%a\ %b\ %d,%l\:%M\ %p`" -fb vga -bg SteelBlue -fg SteelBlue -geometry 24x0+0+0)
For the newer blackbox/bbkeys, I could do this:
[Execute] (Mod1-Control-C) {rxvt -title "`date +%a\ %b\ %d,%l\:%M\ %p`" -geometry 24x0+0+0 -e sleep 3}
I had to add the -e sleep 3 because my recent Bash preferences will overwrite the title with the directory which I’m in.
I now just do this with kdialog:
kdialog --msgbox "`date +%a\ %b\ %d,%l\:%M\ %p`"
[Execute] (Mod1-Control-C) {kdialog --msgbox "`date +%a\ %b\ %d,%l\:%M\ %p`"}
but kdialog required KDE, which is slow to load!
Try something really simple like:
xmessage "`date +%a\ %b\ %d,%l\:%M\ %p`"
.. but maybe that would have to be piped through another program to force the window to appear in a sane place. With Xdialog”
Xdialog --title " " --timebox "Time" 12 25 Xdialog --title " " --calendar "Calendar" 15 32
Could be done a lot easier with a simple infobox.
kdialog --passivepopup "`date`"

I added this into Linux tips and tricks.
2020-06-02 — The original creation was not recorded.