Question

For example, I open a pdf file or a web page in gnome, use mouse double click some text, so a word is selected, how can I get this word in a background running daemon written with python-dbus?

Some simple but working piece of script is appreciated greatly.

Thanks!

Was it helpful?

Solution

You don't need D-Bus, simply listen to changes for the middle-click (Selection) clipboard with for example Gtk:

import gtk

def _clipboard_changed(clipboard, event):
    text = clipboard.wait_for_text()

clip = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY)
clip.connect("owner-change", _clipboard_changed)

OTHER TIPS

Gnome Do has a few plug-ins that use the selected text. I'm not sure how it is implemented (and if it uses DBus), but the code should reveal all. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top