Add a custom option in Nautilus right click menu

Viewed 12304

When a user right-click on a folder in Nautilus, a menu appears. I want to add more options in that menu. I am using Gnome 3.

Is there any other way to customize that menu with command line? Actually I am making a Linux software and I want that these these options should be added when user installs the software.

3 Answers

You might want to use a Nautilus script, which doesn't require any additional installation like for Nautilus Actions.

In order to do that :

  • copy your script in the folder ~/.local/share/nautilus/scripts/
  • make sure it's executable.

It will then appear under the Scripts entry, from the right click context menu like below:

Screenshot of Nautilus script context menu

This answer may be late, but it might be still useful.

No any third party package(s) needed

Write your own script and put it to: ~/.local/share/nautilus/scripts/

An example might be more clear:

If you want to add a Context Menu like Open By VSCode, you can create a file named OpenByVScode.sh with the content:

#!/bin/bash
code -n ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}

then, make it executable;

chmod 744 OpenByVScode.sh

Finally, cope/move this file to ~/.local/share/nautilus/scripts/

The Context Menu is ready to use, which will be displayed under script submenu.

enter image description here

Codes explanation:

First line: #!/bin/bash, to specify which language interpreter needed

Second line: code -n ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}

code is the VSCode default command, option -n means force to open in new window, on the contrary, it also has other option like -r, reuse the current windows, if the software is not open, this option will be the same like -n. For more, please check by code --help.

The variable NAUTILUS_SCRIPT_SELECTED_FILE_PATHS is defined by nautilus, like its name meaning, the path for the selected file or folder. It also has other three type of variables:

1. NAUTILUS_SCRIPT_SELECTED_URIS   : newline-delimited URIs for selected files
2. NAUTILUS_SCRIPT_CURRENT_URI     : current location
3. NAUTILUS_SCRIPT_WINDOW_GEOMETRY : position and size of current window

For more info, please refer HERE

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

Related