Users · Developers · About GNOME · Download GNOME · GNOME Art · GNOME Support · Contact

Welcome to G-Script
Nautilus File Manager Scripts

Questions and Answers

What is a script?

A nautilus script is just an executable shell script (usually bash) that is placed in a special scripts directory so that the Nautilus graphical shell can find it. This is a really neat function of Nautilus, because it allows you to extend the functionality the the file browser to do just about anything.

How do I use them?

Scripts are invoked by selecting a file or group of files, and right-clicking with the mouse, to bring up a 'Context' menu (see picture above.) One of the options of this menu is the 'Scripts' submenu, which allows you to select a script to invoke on the selected files.

How do I install a script

For a script to appear on the script menu, it must: (1) be placed in your scripts directory, and (2) be executable. If you place an executable script is in your scripts directory, its name will not necessarily appear on the scripts menu immediately. You first must 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. By the way, there is a handy script above (make-nautilus-script) that will copy a file to the Nautilus subdirectory and make it executable for you.

Where is my scripts directory?

Prior to Nautilus release 1.0.5, the scripts directory was ~/Nautilus/scripts. Since 1.0.5, it is ~.gnome/nautilus-scripts, although there was some confusion about the scripts directory being in ~/.nautilus/scripts.

I have too many scripts! I can't find any of them.

As of Nautilus version 1.0.5, the scripting menu of Nautilus only recognizes a hierarchical scripts subdirectory. By making subdirectories in your scripts folder, you can arrange your scripts so that they can be accessed more easily, based on what you want to do.
Unfortunately, at least for me, there is a bug so that items inside the subdirectories don't always show up.

How do I create scripts?

I'm not really very good at this, but I can give you a couple pointers. First, you should learn a scripting language. The easiest way to make simple scripts is via bash scripts, but for more complicated tasks, perl, python, csl, GnomeBasic , etc. can be useful. You can find resources for programming Bash scripts here, here, and here.

Basically, a Bash script is just a bunch of Bash commands strung together in a text file. The file should be executable (e.g., with the command chmod u+x [filename]), and the first line should be a special comment of the form #!/bin/sh, which tells the kernel what program to use to execute the rest of the script.

There are a couple of other useful things to know. When a script is invoked, Nautilus sets a few environment variables that can be used by the script:

newline-delimited paths for selected files (only if local)
newline-delimited URIs for selected files
current location
position and size of current window

The selected files can also be referred to with the more traditional "$@" and "$*" bash variables.

The zenity application, available in Zenity, is a simple dialog box you can invoke from a shell script to give the users information or get information from the user. Currently, it seems like it needs a little work, but hopefully it will get more usable in the future.

Help! My script can't handle multiple files/files with spaces

The biggest problem is to be able to handle multiple files with spaces. Many (but not all) of the scripts here are designed to be able to do this, but they require a little thought to construct correctly. Most of the scripts in the "File System Management" (cf. uppercase, lowercase, make-nautilus-script) section are robust for this. If you are not careful, your script will be unable to tell whether a filename with a space is a single file or multiple files. One way is to simply protecting the $@ variable with "$@". Another trick to process multiple files with spaces to use something like this:

					for arg 
					echo "$arg"   #"$arg" must be protected with quotes
This can make it tricky to invoke a single command on all the files at once, and so you may need to iteratively build the commands arguments with a temporary variable. Another solution is to process the input filenames with sed, like this:
					files=`echo "$1" | sed 's/ /\\ /g'`
Some people have found that the above do not work well in all cases. Paolo Bacch suggested the following:
					quoted=$(echo -e "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" | awk 'BEGIN {
					FS = "\n" } { printf "\"%s\" ", $1 }' | sed -e s#\"\"##)
					eval "your-program $quoted"

How do I send you scripts?

If you useful scripts that you would like to see here, please send them to (archives). This mailing list does not archive attachments, so if you want your script to be archived, send it in-line.

If the script is simple (a one-liner), I would suggest you submit it license-free (public domain), because the the licensing material required could make the file hundreds of times larger than the content, and it may make it more difficult for me to make fixes others might suggest, because I am not a lawyer and I don't understand licenses very well. Authors of scripts are acknowledged when available, and I have denoted those scripts licensed under the GPL with a *.

How do I make my script sensitive to file-type?

The unix utility file [filename] can be used to determine what the input filetype is. The scripts filetype and mimetype provide simple examples of how to use this, and pprint provides a more complicated example.

If you want to make Nautilus file-type sensitive, so that a script only will be offered when when a specific type of file is selected, you can add it to your "Open" context menu via the control center's "File Types and Programs" applet.

How can I use these scripts without using Nautilus?

One way to use these scripts is by creating panel launchers or .desktop files (either in Gnome or in another desktop environment), enabling the script to be launched when another file is dragged onto the launcher. For example, these pictures show me dragging files to launchers set up on my menu panel and with a .desktop launcher (the cursors don't appear in the screenshots.) Picture of
					launcher on panel Picture of
					launcher on desktop However, these launchers will do not call scripts with the same arguments that nautilus does, and they will not set up some of the environment variables that nautilus does. So, you should call a modified version of the pseudo-nautilus script available above (modified so that the pseudo-nautilus script runs the script of your choice.) This script will process you commands and call a script in the same way Nautilus will.

How do I make desktop and panel launchers?

The easiest way is to right click on a panel and choose "Panel | Add to Panel | Launcher…", and used the dialog to specify the script and icon you want to use. You should also create the appropriate pseudo-nautilus script, as described above. Alternately, you can write your own. The desktop entry standard (found here) can be used as a reference for creating .desktop launchers, but be warned--Gnome 1.4 does not implement all functionality described in this spec. For example, you don't need to use the '%f' code to pass command-line-like arguments. A simple example .desktop file might look like this:

					[Desktop Entry]
					Name=Junk Sorter
This file is named junksorter.desktop, ~/.panel-scripts/junksorter is a pseudo-nautilus script that launches the junksorter script found above.