↓Skip to main content
  1. Posts/

Always Visible Deadlines

To avoid being surprised by a deadline the day before it arrives, I like to keep upcoming deadlines visible. My solution is to display them in the upper right corner of my computer screen at all times. I use GNOME, but the same idea also works on macOS. It is possible to develop an extension for GNOME Shell directly, but this requires working with some complex and poorly documented APIs. Writing an extension just to display a countdown in the top bar seems like overkill. Luckily, Argos has me covered and simplifies this task enormously. On macOS, xbar provides similar functionality, though the paths and setup differ. Argos is a GNOME Shell extension for creating simple text displays and shortcuts in the top bar. To display text, all I have to do is create an executable that writes to stdout. I opted for a Python script, but shell scripts, C programs, and other executables work just as well. The script should calculate the number of days remaining until each deadline. Easy, right? Right?

#!/usr/bin/env python3

import json
from datetime import timedelta
from datetime import date


with open('/home/myusername/.config/argos/days.json', 'r') as f:
    data = json.load(f)

deltas = map(lambda day: (day['Name'], (date.fromisoformat(day['Date'])-date.today()).days), data)
ordered = map(lambda e: f'{e[0]}:{e[1]}', sorted(deltas, key=lambda x: x[1]))

print(','.join(list(ordered)))

The script reads all deadlines from a JSON file, calculates the number of days between today and each deadline, sorts the results, and prints them separated by commas. The JSON file, called days.json, looks like this:

[
    {"Name": "ApG", "Date": "2021-09-07"},
    {"Name": "BAf", "Date": "2021-09-08"},
    {"Name": "VG", "Date": "2021-09-22"},
    {"Name": "BAT", "Date": "2021-08-16"}
]

The Name field contains an abbreviation to keep the output concise. days.json can be edited manually or updated by another program, for example one that uses my calendar’s API. I place the script at ~/.config/argos/days_left_json.1h+.py. The 1h+ part of the filename means that it runs every hour and whenever I open its dropdown menu. See the filename documentation for all options. The script’s working directory is not necessarily the directory containing the executable. I therefore use an absolute path to days.json.

That’s all. Simple, right?

Some people might object that they do not want to see all their deadlines all the time. I think it is better to keep deadlines visible than to try to remember them or check the calendar sporadically. An easy change would be to show deadlines only during work hours or add a “hide for X minutes” button.