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.
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