I read an article about using python and dbus to automate some stuff with Tomboy Notes and was inspired to do some coding of my own.

In a Nutshell

Use the code below (and a cron job) to automatically delete Tomboy notes that were last modified more than 30 days ago and never placed in a notebook. This will prevent unimportant notes from cluttering up your collection.

Background

Tomboy notes is something I’ve gone back and forth with. Sometimes I use it, sometimes I use Evernote. I’ve had a tough time deciding which I like more, but I’m leaning towards Tomboy these days since it’s fast, free, and runs on linux.

i3wm and the Scratchpad

I started using Tomboy a lot when I found i3wm and discovered the scratchpad function. Basically, you can hide a floating window and hit a hot-key combo to toggle it’s visibility.

I had a Tomboy note called Scratchpad that I would load and keep in i3’s scratchpad so I could put random bits of code and stuff in it. The problem was, though, that I rarely deleted anything. Instead, it grew to a monster disorganized mess.

A new tactic

What I decided to do was to make new notes on the fly. I created a hot-key in i3 to launch a new Tomboy note tomboy --new-note. New notes are not placed in any notebooks, so the Unfiled Notes category easily identifies them.

If I make these temporary ad-hoc notes as new unfiled notes, then they can accumulate in the Unfiled Notes category and if I don’t touch them in 30 days or so, they must not be that important, so I can automatically delete them.

Ah, but how to automate that…

Auto-Delete Old Unfiled Notes

Using python, it wasn’t too hard to script a utility that will loop through all notes and delete any that are both older than 30 days old and not in any notebooks. I moved this into my cronscripts folder and set cron to run it at 12:55 AM every day.

Here’s the code for delOldTomboyNotes.py:

#!/usr/bin/python
import dbus, datetime

thirtyDaysAgo = datetime.datetime.now() + datetime.timedelta(-30)

#Get the D-Bus session bus
bus = dbus.SessionBus()
#Access the Tombox D-Bus object
obj = bus.get_object("org.gnome.Tomboy","/org/gnome/Tomboy/RemoteControl")
# Access the Tomboy remote control interface
tomboy = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl")

#Get all notes
allNotes = tomboy.ListAllNotes()

#loop through notes
for note in allNotes:
    tags = tomboy.GetTagsForNote(note)
    if all(u'system:notebook' not in s for s in tags):
        if all(u'system:template' not in t for t in tags): #weed out templates
            changeDate = datetime.datetime.fromtimestamp(int(tomboy.GetNoteChangeDate(note)))
            if changeDate < thirtyDaysAgo: #changed more than 30 days ago
                #print("Delete this note!")
                tomboy.DeleteNote(note)