Contents |
Introduction
A nautilus script is an executable shell script that is placed in a special scripts directory so that the Nautilus graphical shell can find it. This allows you to extend the functionality of the file browser to do just about anything.
Scripts are invoked by selecting a file or group of files, and right-clicking with the mouse, to bring up a context menu. One of the options in this menu is the 'Scripts' submenu, which allows you to select a script to invoke on the selected files.
Note: The submenu 'Scripts' only appears once you have at least one script in the scripts directory.
For a script to be found by Nautilus it needs to be located in your scripts directory (~/.local/share/nautilus/scripts/, before Ubuntu 14.04 that was '~/.gnome2/nautilus-scripts'). This folder is located in your home folder but is hidden by default. To view hidden files and folders in Nautilus press Ctrl+H, or use the terminal to navigate to the folder:
cd ~/.local/share/nautilus/scripts/
Note: Once you place a script in your scripts directory, it's name will not necessarily appear in the scripts menu immediately. You might have to visit the scripts directory with Nautilus - which can be done using the last option in the scripts menu. Once the directory is visited, Nautilus will know about which scripts you have, and you will be able to use them.
For scripts to be usable they need to be marked as executable. To make a script executable either right-click a script and select 'Properties → Permissions → Allow executing file as program' or use the following command in the terminal:
chmod +x name-of-script
Making a script
To write a script you need to be familiar with a scripting language. The easiest way to create a script is using Bash, but for more complicated task you might need to use other launguages such as Perl or Python.
Whenever a script is called, Nautilus automatically sets a handful of variables that can be used in your scripts.
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
- newline-delimited paths for selected files (only if local)
NAUTILUS_SCRIPT_SELECTED_URIS
- newline-delimited URIs for selected files
NAUTILUS_SCRIPT_CURRENT_URI
- current location
NAUTILUS_SCRIPT_WINDOW_GEOMETRY
- position and size of current window
To see samples of scripts click here.
External Links
http://g-scripts.sourceforge.net/ - More information about Nautilus scripts
http://mundogeek.net/nautilus-scripts/ - A collection of Nautilus scripts