Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom option in Nautilus right click menu [closed]

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.

like image 714
PRATEEK AGRAWAL Avatar asked Dec 04 '22 21:12

PRATEEK AGRAWAL


2 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

like image 85
remjg Avatar answered Dec 11 '22 16:12

remjg


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

like image 24
Xiang Avatar answered Dec 11 '22 16:12

Xiang