Highlight the current date on a GeekTool 'cal' geeklet

Oct 29, '09 07:30:03AM

Contributed by: Anonymous

I've noticed that a number of people (in addition to myself) like to display the output of the cal utility in a GeekLog geeklet (see this older hint, for example).

Unfortunately, there's no easy way to highlight the current date in the output, and the only workaround I've seen mentioned is to run the output through awk to put braces around the current day. That's a bit ugly for my taste, so I endeavored to find a way to highlight the current day with another color.

My solution uses perl, and instead of putting braces around the current date, it replaces everything but the current date with a space, and strips out the header lines (the month and the weekdays):

cal | perl -wne 'BEGIN{chomp($d = `date "+%e"`)} if (/^ *\d/) {s/\b$d\b/"#" x length($d)/e; s/\d/ /g; s/#+/$d/g; print}'

To use this, you make two calendar Geeklets in GeekTool: one which displays the normal output of cal, and one which displays the output of the above command with the text in a different color (I chose yellow), both in a monospace font, of course. Finally, you position the single-day calendar precisely over the full-month calendar, so that the highlighted day sits exactly over the current day.

As the day changes, it should always align with the full-month calendar behind it, making it appear as though the current day is highlighted. The end result is seen in the image at right.

There's one caveat: GeekTool does weird things to the spaces if you center the single-day calendar output, so you'll need to make sure that at least that Geeklet is left-aligned. The full-month calendar can still be center-aligned, though.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091014220449591