Combining calcurse and conky

I’ve finally found a way to remind myself of important dates! Although it is a little too late now to use it really effectively (I’ve already finished my studies at university at which time I really could have used this), I think it will still find its use. What I’ve been looking for all the time is a tool which can organize dates and put them out in an interpretable format on the command line. The tool I found which does exactly that and exactly the way I want it is called calcurse.

As the name denotes, calcurse features a curse-based interface to organize your dates and a todo-list. It has extremely few dependencies and is very customisable. However, for me to be reminded all the time, the organized dates need to be present on my desktop all the time to increase the chance that I’ll actually have a look at them ;) So I installed conky and started investigating on how to get it to display the dates from calcurse.

Configuring conky

conky can be configured to run shell scripts and read and interpret their output with the help of the execpi command. By default, that command has a rather limited buffer which we should first increase so that it won’t cut off the end of the script’s output:

text_buffer_size 512

Now we need a way to define the format of our script. We could of course just use the font and color commands in the script directly but that would mean we’d have to change the script every time we want to change conky’s colours. Thus, I decided to use templates and color-predefinitions so that the output of the script can be made generic. The definitions might look like these:

# Headline color (SYSTEM, HDD, ...)
color0 Tan1
# Information text
color1 83BF1B
# color of lines next to headline
color2 DarkSlateGray
 
# Headline template
template1 ${font Arial:bold:size=10}$color0 \1 $color2 ${hr 2}

The documentation states that execpi is relatively slow, so we’ll call our update every 5 minutes only, which should be sufficient…

${execpi 300 calcurse -d14 | ~/.conky/calcurse_task_to_conky.pl}
 
${execpi 300 calcurse -t | ~/.conky/calcurse_task_to_conky.pl}

The reason why I don’t combine the -d14 and -t flags in one call to calcurse is that it outputs certain information more than once then. I’ll file a bug on this soon, but until then, this will work just as good.

The script

The script I wrote is already built so that it will work when the creators of calcurse fix the aforementioned bug. It looks like this:

#!/usr/bin/perl
 
my %inited;
 
while( <> )
{
    if( /^to do:$/ )
    {
        # filter "to do:" line
    }
    elsif( /^([0-9]{2})\/([0-9]{2})\/([0-9]{2}):$/ )
    {
        # date of a task
 
        if( ! exists $inited{"task"} )
        {
            print "\${template1 TASKS}\n\$font\${color1}";
            $inited{"task"} = 1;
        }
 
        print "$2.$1.$3\n";
    }
    elsif( /^\s+\*\s+(.+)/ )
    {
        # tasks for a whole day
        print " - $1\n";
    }
    elsif( /^\s+-\s+(.+)/ )
    {
        # time range of tasks with special time
        print " - $1: ";
    }
    elsif( /^[0-9]\. (.+)/ )
    {
        # reminders
 
        if( ! exists $inited{"reminder"} )
        {
            print "\${template1 REMINDERS}\n\$font\${color1}";
            $inited{"reminder"} = 1;
        }
 
        print "$1\n";
    }
    elsif( /\s+(.+)/ )
    {
        # description of tasks with special time
        print "$1\n";
    }
}

Save the code as the file ~/.conky/calcurse_task_to_conky.pl, make it executable and you’re good to go.

Have fun with it!

See also:

Leave a Reply

You must be logged in to post a comment.