Unix tidbits in Mac OS X

Unix has some fun things tucked in its nooks and crannies, and Mac OS X has inherited many of them. For example, the calendar command made it into OS X. I don’t recommend calendar as a way of keeping track of your appointments, but it comes with data files that include all kinds of interesting events. The data files are in /usr/share/calendars. You can look at them in your text editor, but I think it’s more fun to use calendar itself to tell me about the day. Here’s what I’ve done:

First, I created a file called calendar in my home directory. Its contents are pretty minimal.

#include <calendar.world>
#include <calendar.usholiday>

These lines tell calendar to include the contents of two files in /usr/share/calendar. (It’s not a coincidence that the syntax matches that of the C preprocessor--calendar actually calls cpp.) As it turns out, the calendar.world file itself #includes several of the other files in `/usr/share/calendar’, so these two lines account for many events.

In my ~/bin directory (folder), I put an executable shell script called today. It’s also two lines long:

calendar -l 0 -f $HOME/calendar

The -l 0 part tells calendar to report only today’s events. The -l option is for “look ahead” and the argument is the number of days to look.

Since today is executable, I can run it from the Terminal, but it’s more fun to run it from Quicksilver. I’ve set up Quicksilver to catalog my ~/bin directory, so I can

  1. invoke Quicksilver (I use Control-Space);
  2. start typing “today,” stopping when today appears in the left pane;
  3. tab over to the right pane and start typing “run,” stopping when Run […] appears (actually I only had to do this the first time or two--now QS knows that I want Run […]);
  4. Press Return, which causes the output of today to appear in the left pane and Large Type to appear in the right;
  5. Press Return again, and the list of events shows up in the middle of my screen.

The visual response to these steps is shown below. The last one has been shrunk to fit in the blog.

Cute, eh?

Update I added the -f $HOME/calendar part to the shell script because, although it worked fine on my G4 iBook, it started failing when I ran it through Quicksilver on my Intel iMac. The calendar program always looks for the calendar file in the current directory and the Console on the iMac was telling me that the calendar file couldn’t be found. Perhaps Quicksilver runs scripts in your home directory on a G4 but in a different directory on an Intel? Whatever. The script as currently written should work on any machine.