5

I'm a Gnome user and I'm trying KDE 5. When I was using Nautilus (Gnome), I had a bunch of shell script actions that worked on a list of selected file paths given by the variable $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS.

Reading this answer, I am aware that Dolphin actions provide the code %F: A list of files. Use for apps that can open several local files at once. Each file is passed as a separate argument to the executable program.

The problem is that Each file is passed as a separate argument to the executable program, while my scripts are designed to work with the variable $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS.

Ideally, I would like to reuse my old scripts. Is it possible to convert the Dolphin's %F list and set it as the variable $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS for my scripts?

1 Answer 1

3

You can get access to all the arguments passed to a script using $@ in bash, this means technically you can create a wrapper script that first prepares a fake environment variable like this:

 export NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$@
 ./real-script.sh

Of course you can also simply modify your script to use $@ like this if you want instead of the original nautilus variable:

for var in "$@"
do
    echo "x" "$var"
done

Also note in your .desktop file for ServiceMenus you'll want to do something like:

Exec=script %F

Notice that %F doesn't have quotes around it.

1
  • I'm also struggling to get my Nautilus scripts to work in Dolphin service menus. Can you explain to this learner why this magical "$@" has to be modified (at least sometimes) like this: for filename in "${@}"; do convert "$filename" "${filename%.*}.jpg"; done.
    – Sadi
    Jan 25, 2020 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .