Gnome 2.32: Sail Through Your Files With Nautilus


by Paul Arnote (parnote)


It’s quite fitting that it’s named after the infamous ship in Jules Verne’s 20,000 Leagues Under The Sea. The Gnome native file manager, Nautilus, is a powerful tool for navigating and working with the files on your Gnome installation.

Looking at the screen shot, it’s hard to distinguish Nautilus from any other capable Linux file manager. It looks a lot like KDE’s Dolphin, Xfce’s Thunar, or LXDE’s PCManFM. Plus, in a lot of ways, it also functions similarly to all of its desktop brothers.

At the top left section of the Nautilus window, you have access to your home partition, the file system, any extra partitions or drives (such as USB flash drive, USB extermal hard drives, or optical disks), and any network drives.

At the bottom left section of the Nautilus window, you have quick, one-click access to frequently used folders. To add additional folders to the quick access area of Nautilus, just drag the folder icon from the right window pane into its new location in the lower left corner of the Nautilus window.

The right section – literally the rightmost ¾ of the Nautilus window – is dedicated to showing your files and subdirectories.

There are quite a few “hacks” for Nautilus running around out there, but “hacks” might not be the best term here. More than anything, there are quite a few hidden or not-so

obvious settings you can adjust that will make it more useful, and that will customize how it displays file data.

One such place is Tech Drive-In, with their “8 Not-So-Common Nautilus Hacks & Improvements” article. They also have another article that reveals a Nautilus script that will send documents to Google Docs. Just do an Internet search, and you will be flooded with results. Just don’t be surprised when you see an overabundance of Ubuntu related results, given that Gnome is the main desktop environment of Ubuntu. Ubuntu-related or not, you will still find much of the information just as pertinent to Gnome running on PCLinuxOS.

Beyond Aesthetics: Extending Nautilus’s Functionality

Just as with KDE’s Dolphin and Xfce’s Thunar (sorry, but PCManFM doesn’t yet have this ability), you can extend the functionality of Nautilus’s right-click context menu. The tasks you can perform this way are truly only limited by your imagination, and can make file management tasks go from being a chore to being super simple and fast.

It’s very easy to extend Nautilus’s functionality. Basically, anything you can imagine using a bash script for can also be used with Nautilus. That’s because Nautilus uses bash scripts as the basis for its extensions.

To facilitate the use of bash scripts, Nautilus will set some special parameters (known as environment variables) to the bash script that’s being called. These environment variables help making bash scripts to extend Nautilus’s functionality even easier to create and work with. They are listed below.

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

So, you can use traditional ways of enumerating file names or data sent to a bash script, or you can make use of the environment variables set by Nautilus. The choice is entirely up to you, as either will work perfectly fine.

Probably the best way to customize Nautilus’s context menu is to find pre-made Nautilus scripts. There are plenty of them out there on the ‘net for you to choose from. Below, I’ve listed just a few of the sites that I’ve found.

G-Script: this site is dedicated to Nautilus scripts, and has several freebie scripts, separated into categories. You might also want to visit the FAQ there, to learn more about creating your own Nautilus scripts.

My Nautilus Scripts: a collection of useful Nautilus scripts. The scripts are available as *.deb files (for Ubuntu and Debian), or as *.tar.gz archives. PCLinuxOS users will need to download the latter.

125 Nautilus Scripts To Simplify Nautilus: This is a collection of 125 Nautilus scripts, available in a *.tar.gz file. While some are overly simplistic, there are quite a few in the collection that should be useful to you.

Once you have your scripts in hand, you need to place them in the the hidden .gnome2 directory, in your home directory (/home/username/.gnome2), under the /nautilus-scripts subdirectory. Just the mere presence of the script in the appropriate folder is not sufficient. You will need to restart Nautilus for the script to be recognized.

Also, all of the directions say to make the script executable (easily done via the file properties “Permissions” tab). However, I’ve not done this to any of the scripts I’ve placed there, and they all seem to work just fine without the file being marked as executable. I don’t know if this is a weird anomaly on my system, so if your script isn’t working, you might want to check to make sure that it’s marked as executable.

After you restart Nautilus, then your script will then appear in the Scripts context menu, as shown in the screen shot above.

These three aforementioned sites should give you a good start on finding pre-made Nautilus scripts. If you want to find more, just do an Internet search, using “nautilus scripts” as your search term.

Roll Your Own

If you feel so inclined, you can edit and further customize the pre-made Nautilus scripts to perform tasks that give you even more functionality. You can even write your own script from scratch, if you find that more to your liking. Personally, I find it advantageous to alter the pre-made Nautilus scripts to do what I want them to.

Having worked on The PCLinuxOS Magazine for as long as I have, there are a few things that I like to do that help me streamline the production of the magazine. Some of those tasks involve resizing images and placing a one pixel black border around images. Rather than open up an image editing application such as Gimp or MTPaint to perform those simple tasks, it’s much easier to be able to perform these tasks from a special context menu item right from the file manager.

Because my requirements for these tasks are rather precise, I usually have to “roll my own” special functions to get them accomplished from a file manager context menu. So, I looked and found a Nautilus script that used ImageMagick’s “convert” command. The script I found converted any image into a *.jpg file. I then changed the script so that it resized the selected images and placed a one pixel border around the image, all in one step.

Here is the script, in its original form:

#!/bin/bash

while [ $# -gt 0 ]; do
        picture=$1
        jpg_file=`echo "$picture" | sed 's/\.\w*$/.jpg/'`
        /usr/bin/convert -quality 75 "$picture" jpeg:"$jpg_file"
        shift
done

Here is the script after I modified it:

#!/bin/bash

while [ $# -gt 0 ]; do

    picture=$1

    convert -resize 598 -bordercolor Black -border 1x1 "$picture" "600-$picture"

    shift

done

Since I’m not interested in changing the file to a *.jpg file, I completely eliminated the line that starts with “jpg_file.” Next, I altered the “convert” line to resize the image to 598 pixels, then place a one pixel black border around the entire image, resulting in an image that’s resized to 600 pixels wide, and renamed with 600 appended to the beginning of the resized image file name – all in one quick and easy step.

I saved the file to the /home/username/.gnome2/nautilus-scripts directory as Resize600Border. Upon restarting Nautilus, my new script is displayed by its name in the Scripts context menu. So, right clicking on an image file, I can select the script from the Scripts menu, and the image will immediately be resized to 600 pixels wide, with a one pixel black border surrounding it.

Summary

Nautilus is a very capable file manager, and one that is very easily extended with Nautilus scripts. If you are installing Nautilus on a desktop other than Gnome, be forewarned that it pulls in a literal TON of Gnome dependencies.

If you are a Gnome or Nautilus user, you owe it to yourself to explore the possibilities that are available to you, via Nautilus scripts. There are pre-made Nautilus scripts to perform all kinds of actions – from audio and video file conversion, to managing archive files, to sending files via email, to just about anything else that you might be able to imagine. You don’t have to be a scripting guru to make good use of Nautilus scripts. Yet, if you are a script guru, there’s virtually no end to what you might be able to accomplish.