Nautilus is the default GNOME file manager. It is filled with great functionalities, including remote filesystems access via WebDAV, SSH and much more.

But besides functionality it also provides exensibility via user scripts and extensions, without the need to dive too deep into its architecture.

You can either write your own scripts or download other users’ ready-to-use files from G-Scripts. Both will need to be placed in the nautilus-scripts folder, located at “~/.local/share/nautilus/scripts/“. For any executable file located in this folder Nautilus will place an entry in its context menu under “Scripts”.

So let’s get started with a basic bash script that will open a terminal in the current browsing directory. Open you favorite text-editor and type the following:

#!/bin/sh

cd $NAUTILUS_SCRIPT_CURRENT_URI
exec gnome-terminal

Now when right clicking on a file you’ll get an option named as the file, and that will open a terminal in the current directory. Handy right? You can use whatever scripting language you wish, as long as you provide the correct interpreter in the first line.

Here’s another script I wrote to run a command on every selected file:

#!/bin/sh

command=`zenity --entry --title "Execute command" --text "Enter command to execute:" 2> /dev/null`

for arg; do
    exec "$command" "$arg" &
    zenity --notification --text "Called $command $arg"
done

I used Zenity in order to ask the user for input and to provide feedback. I appended “2> /dev/null” at the end of the command so that any error message is not saved in the command variable. The for loop then calls that command on every selected file and runs it in the background, then displays a notification to show the user what exactly was executed. 


That’s all, share and comment for any questions!

Advertisements