Add right click menus to nautilus without nautilus-actions

I want to know how I can add action when the user right-clicks on specific MIME-types or folders without the use of nautilus-actions.

I would be happy if this was possible using Nautilus Scripts as well, but I want them to show up only at specific mime types.

I believe it is possible: Ubuntu One does it.


Solution 1:

You can use Nautilus extension API for that. In particular I recommend Nautilus-Python.

Here's a simple example that adds a context menu item for MIME type text/plain:

from gi.repository import Nautilus, GObject

class ExampleMenuProvider(GObject.GObject, Nautilus.MenuProvider):
    def activate(self, menu, files):
        print 'activated' # do something

    def get_file_items(self, window, files):
        if len(files) != 1 or files[0].get_mime_type() != 'text/plain': return
        item = Nautilus.MenuItem(
            name='SimpleMenuExtension::Do_Something', label='Do Something')
        item.connect('activate', self.activate, files)
        return [item]

You'll need to install python-nautilus and gir1.2-gconf-2.0 packages and place the above Python script in ~/.local/share/nautilus-python/extensions/.