Sept. 7, 2010, 4:11 p.m.
posted by void
Customize the Right-Click Contextual Menu
Write your own scripts to perform custom actions when you right-click on a file, folder, or the desktop, and add templates to make document creation quick and painless. Right-clicking on items on the desktop or in the Nautilus file browser pulls up a contextual menu that allows you to perform operations directly on the item. But you're not limited to just the default options: you can add template documents and scripts to the menu for easy access with a single click. Easy-Access TemplatesRight-clicking on the desktop or in the background of a Nautilus window brings up a Create Document menu item, which normally includes only an "Empty File" item. If you select Empty File, a new file called new file will be created, and you can rename it to anything you like. However, the new file is just a totally empty file. Creating a document this way is essentially the same as running: $ touch "new file"
and about as useful. However, it's easy to add your own templates to the menu. Create a directory called Templates in your home directory: $ mkdir ~/Templates
Any document you place in that directory will now be available through the Create Document contextual menu. If the menu becomes large, you can group items into submenus by placing them in subdirectories within Templates. HTML developers can put a file called HTML File.html in this directory (it will appear as "HTML File" on the Create Document menu) and fill it with the skeleton of an HTML file. If you create a lot of corporate documents using OpenOffice.org templates, copy the templates in, and you'll be able to start a new document in any location by just right-clicking and selecting the template. If you do not see your new templates appear in the menu right away, just log out of GNOME and log back in again. Custom ScriptsYou can also execute custom scripts directly from the contextual menu by placing your scripts into a special directory located inside your home directory: .gnome2/nautilus-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 submenu. (The Scripts menu will not be available unless you have some scripts installed.) When a script is executed via the contextual menu, it is passed a number of environment variables and usually a number of arguments so it can optionally act on the files you have selected. If you execute the script from the context of a local folder on your computer, it will be passed the names of all selected files as arguments. If you execute the script from the context of a remote folder [Hack #20], such as a Nautilus window showing web or FTP content, no arguments will be passed to it. Four environment variables are also set, which you can access from within the script:
There are even packages for various prewritten script collections, such as the Nautilus Subversion Management Scripts and Nautilus Audio Convert packages, which allow you to perform Subversion actions and convert audio file formats by right-clicking on files: $ sudo apt-get install nautilus-script-collection-svn \\
nautilus-script-audio-convert
|

As a simple example, you could place the following into ~/.gnome2/nautilus-scripts/Terminal to give you easy access to a terminal from the contextual menu: