I have a Nautilus script that I would like to modify so it performs a single operation using multiple selected files as input. Can someone please explain how to achieve this?

I tried command $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS and what the script does is execute command file1, then command file2 as two discrete operations. That doesn't work for my use case, instead I need the script to execute command file1 file2.

If it matters, I am using it with the command align_image_stack which needs 2 or more image files as input. I started Nautilus from a terminal to see error messages and I get "align_image_stack: At least two files need to be specified". I've tested a few commands shown below, but all produce the same error message. I think the problem is the variable $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS produces newlines, but I don't know how else to capture selected file paths.

align_image_stack $(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS")
align_image_stack printf("$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS")
echo -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | xargs -I align_image_stack "{}"
  • Have you tried xargs -L 1 or echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | while IFS= read -r filepath; do align_image_stack "$filepath" ; done ? – Sergiy Kolodyazhnyy Jul 4 '18 at 23:35
  • xargs -L 1 produces the error "Precondition violation / Unable to open file '{}'" and the second produces the same error as before, "align_image_stack: At least two files need to be specified". – Tom Brossman Jul 5 '18 at 6:19

I was never able to get $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS working, but here is what did work instead:

command $(echo -n "$@")

I believe this is called command substitution, and the "$@" characters insert all selected files into the command together as input, with the -n argument suppressing newlines after echo lists them.

If you ever need to align and fuse together a group of bracketed photos, here's a Nautilus script which is now tested and working perfectly. It outputs the finished product to your desktop (file name is the current time) and cleans up all temporary files after:

align_image_stack -a BATCH -C $(echo -n "$@") && enfuse -o ~/Desktop/$(date '+%Y-%m-%d-%T').tif BATCH*.tif && rm BATCH*.tif
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.