How do I customize the context menu in Nautilus?

From time to time I come up with ideas of actions I'd like to have available in the context menu of Nautilus. How do I add them there? Is there something like a Thunar UCA plugin for Nautilus?


Solution 1:

Update for Ubuntu 18.04

At the date Ubuntu 18.04 was released Nautilus-Actions was/is no longer available. It also seems to have been superseded by a new program, called Filemanager-Actions, which otherwise looks identical.


To install this program, see this solution.


Nautilus Actions

We may define our own right-click context menu items with nautilus-actions Install nautilus-actions.

  • Run the Nautilus-Actions Configuration Tool either from the Dash, or from a terminal with

     nautilus-actions-config-tool
    

enter image description here

  • In the Action tab give your action a sensible label, e.g. "Open in Terminator" and choose to display this in the selection or the context menu.

  • Next open the Command tab to enter the commands to run

enter image description here

  • Give in the full path to your command (/usr/bin/command_to_run) and program options.

  • After logging out and in again the right click context menu below will be displayed:

enter image description here


Solution 2:

This answer is outdated: a recently updated answer is this one.

App developers wanting to add their app's actions — see this page below, here and here.


Context menus of Nautilus used to be customizable by Nautilus extensions. Be warned that this link leads to archived doc; Gnome devs removed that documentation and no longer support that kind of customization. It may still work though.

You can also place plain shell scripts under the ~/.local/share/nautilus/scripts (~/.gnome2/nautilus-scripts in early releases) directory, and they will appear in file context menu under Scripts submenu.

Solution 3:

One can Use python-nautilus extension as an alternative to nautilus-actions.

To install:

sudo apt-get install python-nautilus

A simple example:

import os

from gi.repository import Nautilus, GObject

class ColumnExtension(GObject.GObject, Nautilus.MenuProvider):
    def __init__(self):
        pass
    def menu_activate_cb(self, menu, file):
         os.system("write here your simple bash command & pid=$!")

    def get_background_items(self, window, file):
        item = Nautilus.MenuItem(name='ExampleMenuProvider::Foo2', 
                                         label='Name of your item', 
                                         tip='',
                                         icon='')
        item.connect('activate', self.menu_activate_cb, file)
        return item,

Copy this python script under ~/.local/share/nautilus-python/extensions and restart nautilus. When you right click on the desktop and select your item, your simple bash command will be executed :)

Solution 4:

November 29, 2016 era Ubuntu 14.04, 16.04 and 16.10 plus earlier versions.

See Nautilus instructions for creating your own script here (Help Ubuntu - Nautilus Scripts How to). Basically you:

  • Navigate to the directory ~/.local/share/nautilus/scripts/
  • Place your script (written in Bash, Perl or Python) there.
  • Mark the script as executable using Nautilus or from terminal with chmod +x script_name
  • Nautilus makes environmental variables available to your script: NAUTILUS_SCRIPT_SELECTED_FILE_PATHS, NAUTILUS_SCRIPT_SELECTED_URIS, NAUTILUS_SCRIPT_CURRENT_URI, and NAUTILUS_SCRIPT_WINDOW_GEOMETRY

There are sample scripts located at (Help Ubuntu - Nautilus Sample Scripts) for e-mailing files, mounting an ISO file, setting files to read only, editing file with gedit ROOT priviledges, opening terminal at current location, etc.

Look through the scripts and take one as a template for encrypting files, uploading to the cloud, compressing to backup or whatever you need to do.