You could’ve possibly seen already this nice utility app for OS X called GeekTool that allows you to put things like output of console commands onto your desktop – with custom font/color/opacity, refresh time etc. So one can easily create a nice desktop clock, or calendar, or RAM/CPU load meter etc. Great, isn’t it?

Well, it turns out things are not so great for calendar case. In calendar one usually wants current date to be highlighted, and since displaying console commands output gives you only a text without any styling formatting, you cannot highlight particular bit of text.

Some workarounds have been done for this – like replacing all texts that don’t match a regular expression pattern with spaces, and thus highlighting current date in a month. Current date was a pattern (for example 24), and any text in the output that wasn’t 24 was replaced with spaces. This resulted in display of current date only, but properly positioned (of course fixed width font has to be used – but I guess this is clear without special explanations). This display was put on top of display of monthly calendar with different setting for font, so this way current date was highlighted.

But if we need a yearly calendar? And we also display things like week numbers? (For example I need this for my work where we have planning for weeks by week numbers) – 24 could match current date but as well a week number (also not current one), so that would be a problem. And well, it would highlight 24-th in all months, not just current one.

The solution to this is a command-line calendar app that would allow display of all the data and/or highlights only, i.e. current month/day of week/date/week number. And that’s exactly what I have written.

Since I’m a Java developer, I didn’t feel like learning a scripting language this time, so I made it in Java – sorry for this (-: I know some Perl script might’ve been more appropriate, but I just didn’t have time to study Perl (or any other scripting lang) just for this little thing.

Actually I didn’t have a lot of time for it at all, so even my Java code is quite messy and needs refactoring. But it works and provides enough features to get the job done well enough.

Run it with parameter -help to get list of supported command line parameters – it has quite a few.

The most important one is -hlonly. Normally jcal would just output whole calendar, but with “-hlonly” it will display only highlights: current month (June), date (24), day of week (Sun) and week number (25). You can see it on the screenshot at the top of the post.

I guess I’ll refactor the code a bit in a future, add some more features (like relative monthfrom/monthto, so you could, say render previous+current+next month in top layer, and current+/-2 months in bottom layer giving you nice scrolling over months etc), and then put out the source code. Though I don’t know when I’ll have time and mood for this.

I already see the code could’ve been rewritten to make things far more extendable by generating vectors of textual data for all things like list of weekdays (sun, mon, tue etc), week numbers; and rendering them within “blocks” for each month – this would make the code much more generic and extendable. But this would also take a lot of time – a bit too much as for such non-essential goal as adding calendar to desktop.