2

Where do you put the scripts that appear in the context menu when you right click in a folder or on a file in Nautilus?

Right click menu in nautilus for custom scripts

(Screenshot from a previous version of Nautilus)

My scripts used to work just fine in older versions, but no matter where I place them now, my scripts don't seem to be picked up by Nautilus.

IQAndreas
  • 3,188
  • 1
    Put them under ~/.local/share/nautilus/scripts. – FedKad Jan 31 '23 at 08:33
  • @FedKad That was it! (I also realized the scripts weren't showing up because they weren't marked as executable ) Make the comment a full answer and I will accept it. – IQAndreas Mar 07 '23 at 19:37

2 Answers2

1

Based on the documentation, scripts are loaded from three locations in this order:

  1. $XDG_DATA_HOME/nautilus-python/extensions (i.e. ~/.local/share/…)
  2. nautilus_prefix/share/nautilus-python/extensions (i.e. ~/Development/…)
  3. $XDG_DATA_DIRS/nautilus-python/extensions (i.e. /usr/share/…)

After copying a Python script, we're asked to restart Nautilus to ensure the locations are read and any new scripts are loaded.

matigo
  • 22,138
  • 7
  • 45
  • 75
  • That seems to be specific to the nautilus-python package. Is that included by default in Ubuntu 22.10, or is that something you have to install explicitly? – IQAndreas Jan 31 '23 at 10:12
1

I normally put my scripts under my user directory called ~/.local/share/nautilus/scripts. One such sample script is given below:

#!/bin/bash
## Variables: (Refer to: https://help.ubuntu.com/community/NautilusScriptsHowto)
# NAUTILUS_SCRIPT_CURRENT_URI='file://... current directory'
# NAUTILUS_SCRIPT_SELECTED_FILE_PATHS='... each file is terminated with \n'
# NAUTILUS_SCRIPT_SELECTED_URIS='file://... each file is terminated with \n'
# NAUTILUS_SCRIPT_WINDOW_GEOMETRY=1920x999+0+0

echo -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | sed -z 's/.$//' | xsel -b -i zenity --info --no-wrap --no-markup
--title="File name(s) copied to Clipboard:"
--text="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"

You can save the above script as ~/.local/share/nautilus/scripts/CopyFile_Path and make it executable¹. After that, you can select some files in Nautilus, right click and go to the ScriptsCopyFile_Path menu item.

You can also group your scripts under sub-directories of the scripts/ directory. They will be displayed as sub-menu items in the right-click menu.

For more details, please look at another of my answers here.


¹ Refer to the man pages of xsel and zenity commands. If you don't have these commands on your system, you will have to sudo apt install xsel zenity.

FedKad
  • 10,515