In a default Ubuntu setup, right-clicking a file offers the opportunity to open it with an application, or delete it, rename it, and so on. Wouldn't it be useful if you could add your own right-click option that performed a specific action on the file? For example, if you right-clicked a Microsoft Word or OpenOffice.org document, how about if a Print document option appeared? If you right-click an image, how about if an option appeared to shrink the image, or sharpen it?
All of this is possible using the Nautilus Actions add-in. As its name suggests, this lets you add options to the right-click menu that perform certain actions on particular types files. It's very simple to create your own action but hundreds of ready-made scripts are available and can be imported easily.
To install Nautilus Actions, use Synaptic to search for and install nautilus-actions. Once installed, the configuration program can be found on the System ^ Preferences menu.
Let's take as an example adding a Print document option that will appear whenever a word processing document is right-clicked. This takes advantage of the fact that OpenOffice.org Writer can be used from the command-line to print any document by using the -p command option, without
Do just about anything to a file by right-clicking it M 344
actually starting the program in editing mode—for example, oowriter -p filename.doc.
Here are the necessary steps (these steps can, of course, be adapted for any type of file and/or action):
1. Start by running the Nautilus Actions Configuration program, which can be found on the System ^ Preferences menu. When the program window appears, click the Add button.
2. In the Label field of the dialog that appears, type Print document. This is the text that will actually appear on the right-click menu and can be anything you wish. You can add some text to the Tooltip menu too—this will appear if the mouse is hovered over the menu option. However, it isn't essential. You can also select a suitable icon from the icon dropdown. This will appear alongside the new entry on the menu but, again, it isn't essential.
3. In the Path field, type /usr/bin/oowriter. Most programs you use every day can be found in /usr/bin, and it's necessary to provide the path to the program along with its command-line filename. If you are in any doubt as to where an application "lives," open a terminal window and type whereis command, replacing command with the name of the command in question.
4. In the Parameters text field, specify any command options that are needed, along with the filename and path. For our particular example, we need to type -p and then %d/%f, so the line reads -p %d/%f. %d and %f are Nautilus Actions shorthand—%d refers to the path of the file that's been right-clicked, and %f refers to the filename itself. The slash in the middle separates the two, just like at the command-line. As you type, an example of the command that will be executed appears at the bottom of the dialog box. This is effectively what you would type at the command-line to run the same command, so you can check to ensure it makes sense.
5. Click the Conditions tab. Here we can ensure that the new Print document option only appears whenever we right-click word processing document files, and not any others. We do this by specifying file extensions in the Filenames text field—several extensions can be entered but they must be separated by a semicolon (;). Most word processing documents you're likely to encounter will be .doc, .sxw, .rtf, or .odt files. If you know you will encounter others—for example, WordPerfect documents (which use the .wpd file extension)—
jidd =i iJajj ¿iailiui
Menu Item & Action Conditions Advanced Conditions
Appears if file matches hi I en a mes :+:.doc:+.5xw:+.rtt:+:.odt|
(7! Match case
Appears if selection contains
□ Appears if selection has multiple files or folders
Figure 3.54: Nautilus Actions configuration (see Tip 295, on page 343)
then add the relevant file extension. Precede each file extension by a wildcard (an asterisk). See Figure 3.54 for an example. Once done, click OK. Click the Close button on the main Nautilus Actions configuration window.
Following this you can test your new action by right-clicking a word processing document and selecting the new option—it will appear about two thirds of the way down the menu. Try right-clicking other non-word processing files too and note how the option doesn't appear. If the menu option doesn't appear when it should, try logging out and then back in again.
Note that, if you find it annoying that the OpenOffice.org splash screen appears even when just printing a file automatically, see Tip 197, on page 236 for details of how to turn it off.
Importing configurations made by others
By visiting http://www.gmmz.net/index.php?q=configlist you can download Nautilus Action schemas (effectively configuration files) for just about any task you might want to do to any kind of file. To download a schemas file [[Author: sic - with an s]] , click on the header in the list and then click the schemas link to download.
Be sure to read the schemas description to see if any particular software is needed. For example, schemas that manipulate images will almost certainly need the ImageMagick software installed, so use Google to search for it. Schemas that manipulate video files fill probably need the ffmpeg software installed. Bear in mind that the notes alongside each schemas are probably not written specifically for ubuntu users, so don't name specific packages you'll need. You might have to use common-sense when searching through synaptic's package archive.
Once the schemas has downloaded, open Nautilus Actions Configuration (System ^ Preferences menu) and click the Import/Export button. Then click the button to the rigt of the File to Import text field and browse to the schemas file. Then click the OK button, and then the Close button in the Nautilus Actions parent window. The new menu option will appear immediately although you might have to log in and out again to see the icon (if applicable) appear alongside its entry in the list.
Was this article helpful?