Navigating Nautilus


Nautilus is the graphical file browser that is incorporated into the GDM. It enables you to graphically view files, navigate directories, and start applications when you double-click icons. Besides appearing as a window with files in it, Nautilus also manages the desktop-the desktop is just another file folder that is open all the way.

You can create a button to quickly start Nautilus.

  1. On the top panel, right-click to bring up the menu.

  2. Select Add to Panel. This brings up the applet.

  3. Click the Custom Application Launcher button.

  4. Type Nautilus for the Name field of the button and nautilus (lowercase) as the Command field.

  5. Choose an appropriate icon. I like /usr/share/icons/gnome/48x48/apps/ file-manager.tif.

  6. Click OK to create the button.

Nautilus has many configurable items that are similar to other operating systems. For example, you can set the background in the Nautilus window to be a color or an image. There is also a side pane (View image from book Side Pane) that can list information about the directory or show the directory tree.

Beyond these common features, Nautilus offers a few uncommon features, such as emblems, scalable icons, and customized context-sensitive menus.

image from book
Configuring Nautilus

Even though Gnome uses Nautilus for directory navigation, Nautilus is not the same as Gnome. This distinction becomes very apparent when customizing the system. Gnome uses gconf-edit to manage all configuration options. Any changes to this registry take effect immediately.

In contrast to Gnome, Nautilus uses a variety of configuration methods, and few take place immediately. To tell Nautilus about changes, your best option is to restart it. The command nautilus -q tells Nautilus to quit. Gnome will immediately restart Nautilus and new configuration changes will be loaded.

image from book

Embracing Emblems

Emblems are small accents that you can add to a file or directory icon. For example, critical files can all be tagged with an urgent emblem, and finance files can have a dollar sign on them. Emblems appear at the corner of the icons, so you can easily enable four emblems per file. There are many different ways to enable emblems:

  • Properties-You can right-click an icon and select the properties option. In the properties menu, select the Emblem tab. This enables you to put a check box next to the desired emblem. If you select multiple files, then you can view the preferences and enable all of their emblems at once.

  • Backgrounds and Emblems-Under the Nautilus menu you can select Edit image from book Background and Emblems. A dialog box appears that enables you to drag over a different background (patterns or colors) for the Nautilus window. There are also icon emblems. Just drag the emblem onto the file icon and it will be set (or if it is already set, then it will be removed).

  • Side Pane-The Nautilus side pane has a pull-down menu that displays the emblems. As with Backgrounds and Emblems, you can drag the emblem onto an icon in order to enable or disable it.

Emblems provide visual cues about a file's purpose, but they have little use beyond human interpretation right now. You cannot automatically select files or sort them by emblem, enable emblems on subdirectories, or programmatically change them (without some serious programming efforts).

image from book
Practical Uses for Emblems

Although emblems have no functionality beyond human interpretation, they can be very usable. For example, I have a friend who is a freelance writer. She uses emblems to denote the status of different articles. One emblem denotes a submission, a different emblem marks a sale, and a third indicates work in progress.

image from book

Technical Details

Emblems are stored in a set of XML files found in $HOME/.nautilus/metafiles/. There is one XML file per directory, and only customized directories are present. You can edit these XML files to make system changes, but you'll need to restart Nautilus for the change to take effect.

Listing 2-2 shows a simple script for changing emblems. In this case, every icon with the "special" emblem is changed to have an "important" emblem. More complicated scripts can be created to add emblems to specific files, manipulate files according to their emblems, or to set an emblem based on an event. For example, if an "important" icon is more than 48 hours old, then it can be set to "urgent" or an e-mail notification can be generated.

Listing 2-2: Script to Change "Special" Emblems to "Important"

image from book
     #!/bin/sh     # for each of the meta files...     for i in ~/.nautilus/metafiles/* ; do       # convert any "important" emblems to "special"       # save the result to a temporary file       cat $i | sed -e 's/name="special"/name="important"/g'       # move the temporary file into place       mv $i.new $i     done     # restart Nautilus so the changes take effect     nautilus -q 
image from book

Stretching Icons

One of the coolest features in Nautilus is the ability to stretch icons. You can take any icon on the desktop and scale it-making it very tiny or extremely large. If the icon denotes a text document, then it can be scaled large enough to read the text. To scale an image:

  1. For desktop icons, right-click the icon to bring up the icon's menu and select the Stretch Icon menu option. For icons within a Nautilus directory window, select the icon and choose Edit image from book Stretch Icon from the Nautilus menu bar.

  2. When you select Stretch Icon, four blue dots appear on the corners of the icon.

  3. Grab one of the blue dots (left mouse button) and drag it. This will stretch or shrink the icon.

One great use for stretching icons is to uncluttered desktops. When I'm working on a project, I may end up having dozens of files on my desktop. Before going to lunch, I can stretch the current file to a larger size-this way, I can find it quickly when I get back. Figure 2-8 shows a couple of stretched icons.

image from book
Figure 2-8: A regular icon, a shrunk icon, and a stretched icon that is very large. Icons for text files show the file contents.

To un-stretch the icon, bring up the icon's menu and select Restore Icon's Original Size.

Note 

Under the previous section on emblems, I mentioned that you can have up to four emblems per icon. That isn't exactly true. Emblems are placed along the sides of the icon. If the icon is stretched to a very large size, then you can have lots of emblems without any overlap.

image from book
Stretching Exercises

Stretching icons is still a work in progress for Nautilus. As a result, not all options are available all the time. For example, when an icon is on the desktop, there is a menu option to stretch the icon's size. But the stretch option is not on the icon menu when an icon is selected from inside a Nautilus window. Instead, you need to use Edit image from book Stretch Icon.

Nautilus enables you to drag and drop a stretched icon into a folder-and it will retain the stretched dimensions. Unfortunately, dragging an icon will lose the Restore Icon's Original Size menu entry. In order to restore the icon's size, you will need to first stretch the icon. This reactivates the Restore menu option.

image from book

Technical Details

As with emblems, the stretched value is saved in the $HOME/.nautilus/metafiles/ XML files. Scripts can be created to manipulate the size of the icons. This way, important files can be suddenly made larger. A great use, for example, would be to increase an icon in size right before an online meeting. This way, you can quickly find the files you need. As with emblems, any automated changes to the stretched value require you to restart Nautilus before they take effect.

Adjusting Fonts

The System image from book Preferences image from book Font applet enables you to set font types, but not font colors. The default font uses white lettering with a dark shadow. Although this font is nice when you have a dark (or brown) background, it can appear hard to read with a light colored background. Changing the font color under Nautilus requires a $HOME/.gtkrc-2.0 file. In your favorite editor, create (or edit) this file. Add or modify a section for desktop icons:

 style "desktop-icon" { NautilusIconContainer::frame_text = 1 NautilusIconContainer::normal_alpha = 0 text[NORMAL] = "#000000" } class "GtkWidget" style "desktop-icon" 

In this example, the font color is set to black (#000000). The frame_text value indicates that you are specifying the text format, and the normal_alpha field controls the transparency of the font (0 is not transparent). After editing the file, you can save your changes and restart Nautilus (nautilus -q). The text color matches your setting and (hopefully) offers a higher contrast than the default colors.

Tuning Templates

On the Nautilus menu (including the desktop menu) is an option called Create Document. The Create Document option enables you to make a new file that is based on a template file. By default, there is only one template file-empty file. This creates a zero-sized file just as if you ran the touch command. You can create your own templates by placing files in a Templates directory.

  1. Create a directory called Templates in your home directory.

     mkdir $HOME/Templates 
  2. Place any template file in this directory. The template file name (without extension) appears in the Create Document menu.

For example, you can start up Open Office (Applications image from book Office image from book http://www.OpenOffice.org Word Processor) and save an empty file called WordProcessor.doc in the Templates directory. As soon as you save it, you will have the WordProcessor option listed in the Create Document menu. Selecting this menu option creates a file called WordProcessor.doc, with the name WordProcessor highlighted for renaming.

Scripting Menus

The single most powerful feature of Nautilus is the ability to create context-sensitive menu items. For example, you can create a special menu item that only appears when you select an MP3 file. You can control the types of files, directories, or both where the menu item appears, and whether it appears for one selected item or multiple selections.

To do this, you will first need to install Nautilus Actions:

 sudo apt-get install nautilus-actions 

Now you can create custom menus. For example, here's a menu for securely deleting files (see Figure 2-9).

  1. Run nautilus-actions-config. This brings up the configuration menu.

    Tip 

    You can also find this tool on the top menu under System image from book Preferences image from book Nautilus Actions Configuration.

  2. Click Add to create a new menu script. A new window opens.

  3. For the label, enter Secure Delete. This is the text that will appear on the menu.

  4. You can add a tooltip, such as Safely delete files. This appears when the mouse hovers over the menu item.

  5. Optionally select an icon for this menu item. The icon appears in the menu.

  6. Path is the name of the command that is called. Any command that can be used on the command line can be entered here. For this command, use find (or /usr/bin/find) as the Path.

  7. The Parameters will be passed to the Path command. An example of the command line is displayed below the Parameter field as you type. The %M parameter becomes the list of selected files. If you click the Legend button, you will see other variables that can be used. For this action, use %M -type f -exec shred -u -f ‘{}‘ \;. This parameter tells find to identify all files and run the command shred, forcefully unlinking (deleting) each file.

    Note 

    The shred command does not securely delete directories. The result is a bunch of empty directories. See the Shred Everything entry in Table 2-1 for a solution to this problem.

    Table 2-1: Examples of Useful Custom Menu Commands
    Open table as spreadsheet

    Name

    Path

    Parameters

    Condition

    Notes

    Command Prompt

    . gnometerminal

    g–working- directory ='%M'

    Folders only, no multiple selection.

    Opens a terminal window.

    Open in Firefox

    . firefox

    ‘%M’

    Both files and folders, no multiple selection

    . Keep in mind, Firefox must be opened first; otherwise, nothing may happen.

    Shred Everything

    . bash

    -c ‘find %M -type f -exec shred -u -f "{}" \; ; rm -rf %M’

    Files or folders with multiple selection.

    . Although we can only run one command, this only runs the bash command. The bash argument translates as two commands.

    Convert WAV to MP3

    . bash

    -c "lame %M %d/‘basename %M .wav‘.mp3"

    Only for files ending in .wav, no multiple selections.

    . This converts file.wav to file.mp3 in the same directory. Instead of running lame directly, bash is used to create the subshell basename (used to rename the file). Without the basename program, you would end up with a file named file.wav.mp3.

  8. Under the Conditions tab, you can select when the menu item appears. You can make the selections based on any combination of file name, Meta type, file or directory, and single or multiple selections. In this case, you should select both files and directories (even through directories are not deleted), and allow multiple file selections.

  9. Click OK to add the action to the menu.

  10. Click Close to end the Nautilus action application.

  11. Restart Nautilus so it loads the new menu item.

image from book
Figure 2-9: Adding the Secure Delete menu item

 nautilus -q 

You can test the new menu item by bringing up Nautilus and deleting something. Right-clicking an icon should show the Secure Delete menu item. Selecting the delete item should remove all of the files selected.

Warning 

Shred overwrites files with garbage before deleting. There is no prompt to check if this is what you really want to do, and anything deleted will be gone forever.

Action scripts can be used to convert files (for example, for any GIF, make it a PNG), e-mail a file (such as a Mail To command), or view a file under the web browser. Actions are limited to one command line, but you can specify a shell script for performing multiple-step commands. Some useful custom menu items are included in Table 2-1.

Note 

Only one command can be specified. You cannot use &, |, or ; to join multiple commands.

Warning 

Some commands, such as shred and lame, may take minutes (or longer) to process very large files. During this time, result files (for example, Convert WAV to MP3 files) may be created even though they are incomplete. Requesting the same task multiple times may result in many running processes, that all interfere with each other. The net result may not be what you want. Instead, wait for the task to finish. See Chapter 7 for different ways to monitor processes.



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net