secluded/content/posts/calcurse-notifications.md

4.8 KiB

title description author cover date draft categories tags
Calcurse Notifications Configuring descriptive and attractive notifications for calcurse Amolith /assets/pngs/calendar.png 2020-05-13T22:23:25-04:00 false
Technology
Calcurse
CLI
Notifications
100 Days To Offload

I recently started using calcurse for my calendar and one of its limitations is good notification support in the generally accepted meaning of the word. The developer has a different opinion and that's perfectly alright but traditional notifications are a feature I heavily rely on and calcurse doesn't handle handle them very well; it leaves the user to figure something out on their own. Inspired by one individual's issue, I did just that.

A quick glance at man calcurse reveals this section:

-n, --next
    Print the first appointment within the next 24 hours. The
    printed time is the number of hours and minutes left before
    this appointment.

The output of running calcurse -n, for me and at the moment, looks like this:

$ calcurse -n
next appointment:
   [17:25] DnD on Mumble

It's all well and good but not really something you'd want in a notification; it needs to be filtered down so it only shows the name of the event, DnD on Mumble. To do this, I turned to the man pages of standard CLI utilities tail and cut. tail allows us to filter the output to only the last line1 with tail -1. cut is a little more complicated but will allow us to remove the first few columns of text. cut -d ' ' -f 5- is the next snippet in this one-liner. -d ' ' tells cut to use a single space as the delimiter, -f specifies the fields to keep, and -5 says to use all fields starting with the 5th because there are a few spaces preceding the content we want. Chain all of this mess together with pipes and we get:

calcurse -n | tail -1 | cut -d ' ' -f 5-

Great. Now we need to actually get a notification containing the resulting string. This can be achieved by storing it in a variable then using it with notify-send. You likely already have notify-send installed if you're using Linux but, if you don't, I would recommend looking around to see what's default and using that instead.

CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5- -)" && notify-send "Calcurse Event" "$CONT"

Now we're actually getting somewhere. With my setup, the notification looks like this: It's a screenshot of my desktop with a notificationin the top right corner. The title is "Calcurse Event" and the textbelow is "DnD on Mumble". Surrounding the text is a solid border. Itsposition and the border are all that designate it as a notification: thebackground and text colour match the rest of my desktop which is themedwith the base16-unikitty-dark scheme

It's certainly passable and sufficient for some but I'd like an icon so I can see what the notification is for out of the corner of my eye and decide whether or not to glance over. Thankfully, notify-send has this built in with the -i flag.

-i, --icon=ICON[,ICON...]
    Specifies an icon filename or stock icon to display.

Now it's just a matter of figuring out what icon to use. You can certainly pass the path of whatever image you want to it, such as ~/Pictures/calendar-icon.png, but I want something that fits in with the rest of my icons. These are found in:

/usr/share/icons/<theme>/it/depends/on/theme

I use Suru++ Dark and the icon I'm using can be found at:

/usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg

It's different for Adwaita and all the rest though; you'll have to do some digging. It's also worth noting that, if you don't have this theme installed on another device, the icon won't show up.

After all that, here's my notification command and a screenshot.

CONT="$(calcurse -n | tail -1 | cut -d ' ' -f 5-)" && notify-send -i /usr/share/icons/Suru++-Dark/apps/32@2x/calendar.svg "Calcurse Event" "$CONT"

This is a screenshot like the last one but with an attractive icon tothe left of the text


This was posted as part of #100DaysToOffload, an awesome idea from Kev Quirk. If you want to participate, just write something every day for 100 days and post a link on social media with the hashtag!


  1. The opposite of tail is head and allows for exactly the same thing in reverse: head -1 will return the first line of whatever input it's given. ↩︎