2

I wrote MyScript.sh! MyScript.sh works great from the command line; it takes one or more file paths as its arguments.

In Ubuntu 18.10 how can I:

  1. After selecting one or more files in Nautilus/Files.
  2. Trigger MyScript.sh using the selected file/files as arguments?

I am happy to use either a contextual menu (i.e. right click), or a keyboard shortcut (.e. through Settings > Keyboard > Custom Shortcuts).

Unacceptable answer: I am not looking for someone to tell me to type ./MyScript.sh in the command in a terminal, and then drag-and-drop a file/files onto it from nautilus followed by <ENTER>.

Edit 1: I have tried placing MyScript.sh in ~/.local/share/nautilus/scripts/, ensuring it is executable, and right clicking on a file to apply, but no Script submenu appears.

Edit 2: I have set a Keyboard Shortcut in Settings > Keyboard, but the script does not execute.

Lexible
  • 1,355
  • 4
  • 16
  • 31

1 Answers1

0

Run a script with files selected in Nautilus as argument

  1. Make sure MyScript.sh is executable.
  2. Copy (or move) the script to /home/$USER/.local/share/nautilus/scripts/.
  3. Open Nautilus and select a file (or multiple files).
  4. Right click on the selected file to open the context menu.
  5. Go to Scripts > MyScript.sh

enter image description here

Note: The Menu item Scripts > does not appear until there is a script or any file in the folder /home/$USER/.local/share/nautilus/scripts/. You can see the location of this folder in the top bar of the Nautilus screenshot above.

MyScript.sh will run with the selected files as arguments.

user68186
  • 33,360
  • Thank you, but this does not work on Ubuntu 18.10. I have done (1), (2), (3), (4) .. but I cannot do (5) because there is no Scripts menu when right clicking any file. – Lexible Jan 31 '19 at 19:31
  • @Lexible Thanks for the feedback. I don't run 18.10. My answer was based on 18.04. For you I downloaded 18.10 and used the "Try without installing option in a VM to see if there was any problem finding the Script menu in Ubuntu 18.10. The Scripts context menu does not appear if the special folder where you have to copy the script is empty. If you put a file in the correct folder the context menu item will appear. – user68186 Jan 31 '19 at 21:24
  • Is the "special folder" somewhere other than ~/.local/share/nautilus/scripts? – Lexible Feb 01 '19 at 08:07
  • Just as I wrote in my first comment. – Lexible Feb 01 '19 at 22:06