OK, here are two more scripts I wrote to do useful things with python and Tomboy notes.

tbclip

This first one copies whatever text is currently selected and creates a Tomboy note with it. NB: You must have xclip installed.

#!/usr/bin/python
import sys, dbus, subprocess
#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")

new_note = tomboy.CreateNote()
title = tomboy.GetNoteTitle(new_note)
contents = subprocess.check_output(['xclip','-o'])
new_contents = title + "\n\n" + str(contents)
tomboy.DisplayNote(new_note)
tomboy.SetNoteContents(new_note, new_contents)

I had a really tough time getting dbus to change the contents of a new note. It seems you have to display the note first; otherwise SetNoteContents just doesn’t seem to work… who knows why?

tbnote

Use this next one in the command line. Just pipe the output of some useful command to it and it will create a Tomboy note. (Reads standard input and uses any arguments as the title of the note).

Example: $fortune | tbnote Random Fortune

#!/usr/bin/python
import sys, dbus, time
contents = sys.stdin.read()

def makeNote(title, body):
    #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")
    if title:
        try:
            note = tomboy.CreateNamedNote(title)
        except:
            note = tomboy.CreateNote()
    else:
        note = tomboy.CreateNote()
    contents = tomboy.GetNoteContents(note) + str(body)
    tomboy.DisplayNote(note)
    tomboy.SetNoteContents(note, contents)

if len(sys.argv) > 1:
    makeNote(" ".join(sys.argv[1:]),contents)
else:
    makeNote(None,contents)