There is a special directory ( .gnome2/nautilus-scripts/ ) inside your home folder into which you can put your custom scripts. Any script you place in that location can be accessed by right-clicking on a file or window and selecting it from the Scripts sub menu. (The Scripts menu item will be visible only if you have some valid scripts installed.
Let us try to open a terminal from the contextual menu. Change to the scripts directory. ( Note that .gnome is a hidden directory, try control -h in nautilus to see hidden files. )
$ cd ~/.gnome2/nautilus-scripts/
Create the following script
Save the file as myterminal
Change the permission of the file and make it executable
$ chmod u+x myterminal
Now right click on the contextual menu. You should get it as below.
When you execute a contextual menu script , a number of environment variables are passed to the script from nautilus. For example, if you select some files and then right click and select a script , the list of selected files will be passed to the script as an environment variable . You can use this variable inside the script for further processing.
Some of the variables passed are.
Newline-delimited paths for selected files if they are local
Newline-delimited URIs for selected files
URI for current location
Position and size of the current window
Here is a bare minimum example with which you can try out the use of environment variable.
Suppose you want to open a terminal and change to a particular directory, you can put the following code in nautilus-scripts directory. ( There is no error checking).
if [ -d $mydir ]; then
There are a number of nautilus scripts available on the internet. In the ubuntu 9.04 repository, the following script collections are available.
nautilus-script-audio-convert - A nautilus audio converter script
nautilus-script-collection-svn - Nautilus subversion management scripts
You can also get lot of useful scripts from http://g-scripts.sourceforge.net/.