Score:0

Nautilus script in ~/.local/share/nautilus/scripts/ doesn't show any terminal window or output

gb flag

I've created simple script and put it to ~/.local/share/nautilus/scripts/ (script at the end of the post).

I'm able to run with right click in Nautilus->Scripts->myScript.sh, all good so far.

The problem is there is no terminal window presented or any output. I only receive that notify-send message properly filled with path to selected file without any waiting.

I would expect that there will be some terminal window that will print "THIS IS TEST!", then "PLEASE ENTER..." and waiting for that Enter keypress. Finally after this the notify-send should be received.

What am I missing here?

#!/usr/bin/bash

echo "THIS IS TEST!"
read -r -p "PLEASE ENTER TO EXIT! Waiting..."

notify-send "COMPLETED!" "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS} ___ ${NAUTILUS_SCRIPT_SELECTED_URIS} ___ ${NAUTILUS_SCRIPT_CURRENT_URI}"
Score:2
cn flag

Terminal window is not created automatically. You have to create it yourself. I modified your script as follows:

#!/usr/bin/bash

function commands-to-be-run {
  echo "THIS IS TEST!"
  read -r -p "PLEASE ENTER TO EXIT! Waiting..."
}

export -f commands-to-be-run

gnome-terminal --title="Testing..." --wait -- bash -c commands-to-be-run

notify-send "COMPLETED!" "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS} ___ ${NAUTILUS_SCRIPT_SELECTED_URIS} ___ ${NAUTILUS_SCRIPT_CURRENT_URI}"

I have put all your statements (commands to be run inside the terminal) into a bash function and exported it, so that it can be used by child processes.

Then, I used the gnome-terminal --title="Testing..." command to create a terminal window with an appropriate title. The --wait option will force the gnome-terminal command not to return until the commands to be run after the -- option are finished.

Please, read the man gnome-terminal page for more options.


Depending on you needs, a shorter version might be this:

#!/usr/bin/bash
gnome-terminal --title="Testing..." --wait -- bash -c '
  echo "THIS IS TEST!" ;
  read -r -p "PLEASE ENTER TO EXIT! Waiting..."
'
notify-send "COMPLETED!" "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS} ___ ${NAUTILUS_SCRIPT_SELECTED_URIS} ___ ${NAUTILUS_SCRIPT_CURRENT_URI}"

Look also at the zenity command for more options to do input / output from your nautilus scripts. Here is a very basic example:

#!/bin/bash
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"
keldorn avatar
gb flag
Absolutely amazing!!! Works like a charm, thanks!!! :D
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.