Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Highlight the current date on a GeekTool 'cal' geeklet Desktop
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.
    •    
  • Currently 2.31 / 5
  You rated: 4 / 5 (13 votes cast)
 
[20,705 views]  

Highlight the current date on a GeekTool 'cal' geeklet | 9 comments | Create New Account
Click here to return to the 'Highlight the current date on a GeekTool 'cal' geeklet' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Nice... but
Authored by: jpkelly on Oct 29, '09 10:21:54AM

This is really great but it seems to break on the single digit days.



[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: boob on Oct 29, '09 12:46:26PM
i also wanted to do this and this works fine for me
cal=`cal`; today=`date "+%e"`; echo -en "${cal/${today}/\033[1;32m${today}\033[0m}";


[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: jpkelly on Nov 02, '09 02:13:18PM

i like this because it uses a single geeklet but...
on november 2 the 2 of 2009 was lit up.



[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: boob on Nov 03, '09 02:52:36PM
yop, you are right, didn't notice that.. i fixed it like this (it 's nearly midnight here, so it's not the best solution maybe, but it seems to work :)) i tried to set "today" to few random days and it seemed fine..
cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date -v+14d "+%e"`; echo "$cal_head"; echo -en "${cal_tail/${today}/\033[1;32m${today}\033[0m}";


[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: boob on Nov 03, '09 02:57:26PM
argh.. without "-v+14d" of couse, so it should be
cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date "+%e"`; echo "$cal_head"; echo -en "${cal_tail/${today}/\033[1;32m${today}\033[0m}";
where it "edit" button.. it was here here, wasn't it ? :)

[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: billr on Oct 29, '09 04:59:43PM

The second comment above is an excellent suggestion; it produces a green colour using the ANSI terminal control sequence 1;32 . You can vary this foreground colour by changing the 32 to one of the following values:
Foreground Colours
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White
You can also control the background colour, make the selected date blink, etc.
by appending additional attributes. Google for "ANSI/VT100 Terminal Control" for full information.




[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: tangential on Nov 04, '09 04:40:00AM

The approach using the SMSO and RMSO strings is definitely better.

In my geektool setup, I use cal -y to show me the entire year.

Any ideas about highlighting the current date when a whole year is displayed would be appreciated.



[ Reply to This | # ]
Highlight the current date on a GeekTool 'cal' geeklet
Authored by: jonjlee on Dec 01, '09 02:27:42PM
This (rather ugly) awk-based command should do the trick:

cal -y | awk -v month="`date +%m`" -v day="`date +%e` " '{m=int((NR-3)/8)*3+1; for (i=0;i<3;i++) {t[i]=substr($0,1+i*22,20) " "; if (m+i==month) sub(day,"\033[0;31m&\033[0m",t[i]);} print t[0],t[1],t[2];}'
Change the highlight color using the values billr posted above.
Edited on Dec 01, '09 02:32:28PM by jonjlee


[ Reply to This | # ]
[OT] change GT3 menu icon
Authored by: jpkelly on Dec 03, '09 12:24:36PM

I love GeekTool and was excited to find development is continuing in GeekTool 3 but...

I found that the GeekTool 3 menu icon looked very similar to the displays menu item. Enough to be confusing. So I created an icon to replace it which looks unique and represents GeekTool well. I created an installer to replace the GeekTool menu icon. Installer If you would rather install the image files manually, here is a link to a .zip file containing the the images. GTmenuIcons.zip They get placed in 'GeekTool.prefPane/Contents/Resources/GeekTool.app/Contents/Resources'.



[ Reply to This | # ]