Make tfdbus.py executable.
[tomfox.git] / tfdbus.py
blob08a59e72b7eb6cd632fa9619b0ee7c265c410275
1 #!/usr/bin/env python
3 import sys, dbus, gobject, dbus.glib
5 # Get arguments
6 title = sys.argv[1]
7 note = sys.argv[2]
8 url = sys.argv[3]
9 display = sys.argv[4]
10 notebook = sys.argv[5]
11 appendnote = sys.argv[6]
14 # Format URL for XML
15 if len(url) > 0: url = "<italic><size:small>Source: <link:url>" + url + "</link:url></size:small></italic>\n\n"
18 # Connect to Tomboy DBUS
19 bus = dbus.SessionBus()
20 obj = bus.get_object("org.gnome.Tomboy", "/org/gnome/Tomboy/RemoteControl")
21 tomboy = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl")
24 # Create/Append Note
25 if tomboy.NoteExists(tomboy.FindNote(title)) == 1 and appendnote == "true":
26 uri = tomboy.FindNote(title)
27 currentcontents = tomboy.GetNoteContentsXml(uri)
28 currentcontents = currentcontents.encode('utf-8')
29 separator = "<strikethrough>"
30 for i in range(1, 70): separator += " "
31 separator += "</strikethrough>"
32 tomboy.SetNoteContentsXml(uri, "<note-content>" + currentcontents + separator + "\n\n" + note + url + "</note-content>")
33 else:
34 # Check if title exists, append #1, #2, #3... to the end of the note title
35 if tomboy.NoteExists(tomboy.FindNote(title)) == 1:
36 notedupe = int(1)
37 while tomboy.NoteExists(tomboy.FindNote(title + " #" + str(notedupe))) == 1:
38 notedupe = notedupe + 1
39 if notedupe > 0: title = title + " #" + str(notedupe)
41 # Create the note and set the contents
42 uri = tomboy.CreateNamedNote(title)
43 tomboy.SetNoteContentsXml(uri, "<note-content>" + title + "\n\n" + note + url + "</note-content>")
45 # Assign note to the default notebook
46 if len(notebook) > 0: tomboy.AddTagToNote(uri, "system:notebook:" + notebook)
49 # Display Note if enabled
50 if display == "true": tomboy.DisplayNote(uri)