Nautilus is one of the most commonly used file manager for GNOME. One
of the reasons for its popularity is its extensible architecture that
allows developers to write scripts to customize it. Even if you are a
command line person, extending Nautilus will result in dramatic
increase in productivity. In this post, I will discuss the multiple
ways in which Nautilus can be extended and the relative merits in each
The first step in extending Nautilus is to find the set of actions that are tedious (atleast not straightforward) – Tasks that need
additional clicks or switching to terminal to get completed. The next
step is to determine if there are command line tools available to
automate the task or the task can be completed by additional code –
Again since you are extending Nautilus, the task involved has to
relate to files or folders. For eg, opening a file as administrator is
a "relevant" task but starting a nuclear war from Nautilus is not !
Informally, it is easy to extend Nautilus if your task falls in the
following categories : Adding new entries in context menus (or in
toolbar) that involve selected files/folders or current folder, add
additional custom properties to files and display those details in
list view, modify the properties page to display additional tabs with
information etc. There are other possibilities but these are the most
If the above discussion sounds very abstract let us give some examples :
- Open a terminal in the current folder or open the selected file as root.
- Selecting a few audio files and adding them to Rhythmbox "Now Playing" queue.
- Selecting a few files and sending them to thunderbird for attachment
- Display IMDB details about the selected movie file in the property page etc.
The above examples show a gradient of use cases in the order of
complexity. Some of them are so simple that they can automated using
simple means. Tasks like (4) are tricky and need powerful tools.
Selecting the right tool is important and we will discuss how to
select the best approach.
Different Approaches to Customize Nautilus Context Menus Like
everything in Linux, there is always a variety of ways to customize
Nautilus ranging from simple to complex. In this post, we will discuss
the three most common approaches :
- Using tools like nautilus-actions
- Using Nautilus scripts
- Using extensions written in nautilus-python
As before, all my discussion will be focused on Ubuntu but it should
be relatively easy to apply to other Linux distributions.
Customizing Nautilus context menu using nautilus-actions This is
probably the easiest method. All you need to know is the shell command
or script to perform the task. Nautilus actions provides an intuitive
GUI to decide on the filters and the actions to be performed. This
approach works best if the following conditions are met : a. the task
you want to be automated is easily translatable in command line b.
the command line utility accepts the arguments in a relatively simple
form (eg space separate arguments etc) c. The command line utility
depends only on information pertaining to the selected file/folder.
To install the package, type the following at terminal (or install
this package from Synaptic) :
sudo apt-get install nautilus-actions
Once the package is installed it can be accessed at System ->
Preferences -> Nautilus Actions Configuration. I will only give a
basic discussion here as there is a decent tutorial on how to create a
new action at How To Add Custom Functionality To Nautilus.
Let us take a simple example – If I right click on a folder , I want a
new menu which says, "Open Terminal Here" and when it is clicked, a
new terminal must be opened and the working directory of the terminal
must be the selected folder. The first step is to find if it can be
expressible in a "single" command. Find the name of the command to
invoke the terminal – it is called gnome-terminal. Read the man page
to find that it accepts an argument "–working-dir". When provided, it
starts the terminal in specified folder.
Now start the Nautilus Action from System -> Preferences -> Nautilus
Actions Configuration . The steps are : a. Create an action. b. In
"Action" tab, give the action some name and select "Display item in
selection context menu". If you want it to be visible in the toolbar,
it can done too ! Select "Display item in toolbar" and choose some
icon. c. In the command tab, give "gnome-terminal" as path and
parameters as "–working-directory=%d/%f". The %d and %f are special
codes that will be expanded when the command is invoked. To see other
special codes and what they mean, click on the "Legend" button. d. In
"Conditions" tab, select "Only Folders".
Now open a new Nautilus window , select a folder and right click.
Presto ! You will see a "Open Terminal Here" menu. Select it and you
will see a new terminal open with the selected folder as its current