How to edit the context menus of Nautilus File Manager?

To add menu items to can write a Nautilus extension, like

from gi.repository import Nautilus, GObject

class MyItemExtension(GObject.GObject, Nautilus.MenuProvider):
    def get_file_items(self, window, files):
        menuitem = Nautilus.MenuItem(name='MyItem::SomeItem', 
                                     label='My Item', 
                                     tip='my own item',
                                     icon='')

        menuitem.connect('activate', self.on_menu_item_clicked, files)
        return menuitem,

    def on_menu_item_clicked(self, item, files):
        print [f.get_name() for f in files]

Save this into something like /usr/share/nautilus-python/extensions/myitem.py, install the package python-nautilus and restart Nautilus, for example by running nautilus -q; sleep 2; nautilus. Now you should see a new item "My Item" if you rightclick a file.

As far as I know there is no documented way to remove menu items.

The see API reference for some more information.


This applies only for Nautilus 3.8 and newer.


I know it is not the only place to do it, but you can add context options in the library : /usr/lib/nautilus/extensions-3.0.

The library files need to be .so hexadecimal libraries.

I think the other way to do it would be to modify the source code of Nautilus.

EDIT: This is no longer true at least as of whatever Gnome shipped with Ubuntu 18.04. Researching online it looks like this feature was completely pulled from Gnome, as per this Redhat bug discussion: https://bugzilla.redhat.com/show_bug.cgi?id=885088 Though it does appear that the share dialog UI can be changed via /usr/share.nautilus-share/interfaces.