36

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?

1

6 Answers 6

38

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


4
29

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.

5
  • 3
    Please note that as said in askubuntu.com/questions/281062/… if you are on ubuntu 13.04 which uses a newer version of Nautilus, you are supposed to use ~/.local/share/nautilus/scripts folder to put your scripts in. And even then it will only show up scripts when you right click on a file or folder and not empty space.
    – Logan
    Jul 3, 2013 at 14:59
  • 2
    isn't this outdated?
    – user47206
    Mar 25, 2017 at 11:23
  • @cipricus it is. Answered on 2011, which is uh 6 years ago. 12 Ubuntu releases earlier.
    – ulidtko
    Mar 26, 2017 at 6:14
  • the question is not marked as edition specific and there are very recent answers
    – user47206
    Mar 26, 2017 at 16:54
  • It's disconcerting to read: "devs removed that documentation and no longer support that kind of customization. It may still work though." Jun 12, 2021 at 3:35
12

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 :)

3
  • you may need to create nautilus-python and extensions folders if they are not there.
    – sourav c.
    Jun 11, 2014 at 14:38
  • I tried most of the solutions in this topic and found that the python solution is the best one. Although not perfect, mainly because of lack of documentation, it allows for more flexible scripting and portability. Mar 5, 2017 at 23:33
  • I recently upgraded from Ubuntu 20.04 to 20.10. The package python-nautilus is not available on apt. Is there any ppa for this package?
    – Eiman
    Nov 6, 2020 at 19:47
6

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.

2
  • 1
    This still works in Ubuntu 21.04.
    – ph0t0nix
    Jun 11, 2021 at 8:17
  • 1
    @ph0t0nix Thanks for the 21.04 update. Also thanks for the edit. Jun 11, 2021 at 11:08
4

TL;DR

The best solution for app developers is to use python-nautilus.

Create your python script (following examples and bad documentation) and copy it to the correct folder:

mkdir -p ~/.local/share/nautilus-python/extensions && cp script.py ~/.local/share/nautilus-python/extensions

Detailed Explanation

Let's say you want to create an application that the user installs with a script or a .deb file, with that in mind I'll be explaining why I think python-nautilus is a better solution compared with nautilus-actions and the nautilus scripts.

Nautilus Actions

This is the only solution to offer a GUI and therefore makes it easy to create complex behavior, for example decide what menu entries to show if the selected file's mime-type is text/plain.

The main problem with this solution is that it is not easy (if even possible) to import the entries to another computer without the Configuration Tool and the user importing it, let's just say it would not be possible to do with a script.

Nautilus Scripts

This is the more straight forward solution, pick up a script, place it in a folder and done. This would definitely allow a install script or a .deb file to create a new entry in the context menu. What are the problems? Where do I start...

  • It always appears under a Scripts sub-menu.
  • It doesn't show if you have nothing selected.
  • It doesn't allow you to decide if you should show the entry or not.
  • Does not allow Tooltips or different Titles. (maybe I'm being picky)

A good app doesn't use shortcuts like this, because it ruins the user experience.

python-nautilus

Not as easy to create as the previous solutions, but offers the best of both worlds. Scripting and customization.

This solution allows you to create a python script that receives the files selected in nautilus and let's you decide if you wish to show a entry or not and what to do with that entry. It also allows you to create sub-menus and or cool stuff.

The drawback is the big lack of documentation and developers that just want to add an entry may find themselves losing a couple of hours to create a working prototype (In my research I found a solution based on C that was way more complicated than this).

I normally use Visual Studio Code, while on Windows it offers a context menu entry Open with Visual Studio Code, it's lacking the same functionality on Linux, with the Python solution it would be easy to solve the problem. I think may apps in Linux could benefit from having a nautilus integration.

Hope this explanation helped you decide what to choose.

2
3

If you want to be able to do something at any time, do like ulidtko says and use ~/.gnome2/nautilus-scripts.

If you want to be able to customize when you see it, install the nautilus-actions package, then go to System->Preferences->Nautilus Actions Configuration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .