ulrik@kaizer.se/ log/ post/
nautilus selection over dbus

Accessing Nautilus' selection over D-Bus, and get live updates.

The new version of kupfer, c11, has Quicksilver-esque proxy object support for the currently selected file in Nautilus. Kupfer already had support for the currently selected text (it is always in the X clipboard, easy); but I thought nautilus integration would be impossible without upstream collaboration.

Not so impossible. I wrote a quick nautilus extension (actual file) that has to be installed, and once installed, it broadcasts the current selection and when it changes over the D-Bus:

$ nautilus
Initializing KupferSelectionProvider
Initializing nautilus-open-terminal extension
...

Install the plugin (done by kupfer), and watch the beatuy unfold with dbus-monitor when selecting files in Nautilus:

signal sender=:1.813 -> dest=(null destination) serial=32
path=/se/kaizer/kupfer/NautilusPlugin;
interface=se.kaizer.KupferNautilusPlugin; member=SelectionChanged
   array [
      string "/home/ulrik/pt"
      string "/home/ulrik/Sites"
   ]
signal sender=:1.813 -> dest=(null destination) serial=33
path=/se/kaizer/kupfer/NautilusPlugin;
interface=se.kaizer.KupferNautilusPlugin; member=SelectionChanged
   array [
   ]

Watch that! Instant notification over D-Bus when selection is set or reset! Multiple selection supported.

How does this work? Well, with the Nautilus extensions API, you can add some types of objects. The key here is the MenuProvider; it will be called once for each selection, to find out if the Extension wants to add a context menu or Edit menu item (for example, some extension adds "Upload to Flickr"). The Kupfer Extension listens in, secretly transmits the information over D-Bus, and says it doesn't want to add a thing!

Obligatory screenshot

screenshot working with kupfer's selected file

Comments? To kupfer's mailing list; kupfer-list (at) gnome dot org