Saturday, October 11, 2008

Nautilus Actions: Do just about anything to a file by right-clicking it

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 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 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 the aptly-named nautilus-actions package. Once installed, the configuration program can be found on the System —> Preferences menu.

Creating a Configuration from Scratch

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 Writer can be used from the command line to print any document by using the -p command option, without 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 box that appears, type Print document. This is the text that will actually appear on the right-click menu and can be anything you want. 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 drop-down list. 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 has 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 appears only 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)—then add the relevant file extension. Precede each file extension by a wildcard (an asterisk). For an example, see the screenshot below. Once done, click OK. Click the Close button on the main Nautilus Actions configuration window.
  6. After 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. Also try right-clicking other files that aren’t word processing files, 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.

Importing Configurations Made by Others

By visiting, you can download Nautilus Actions schemas (effectively configuration files) for just about any task you might want to do to any kind of file. To download a schemas file, click the header in the list, and then click the schemas link to download.

Be sure to read the schemas description to see whether any particular software is needed. For example, schemas that manipulate images will almost certainly need the ImageMagick software installed, so use Synaptic to search for it. Schemas that manipulate video files will probably need the ffmpeg software installed. Bear in mind that the notes alongside each schema are probably not written specifically for Ubuntu users, so don’t name specific packages you will need. You might well have to use common sense when searching through Synaptic’s package archive.

Once the schemas have downloaded, open Nautilus Actions Configuration (System —> Preferences menu), and click the Import/Export button. Then click the button to the right of the File to Import text field, and browse to the schemas file. Click the OK button, 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.

No comments:

Blog Archive

About Me

Exclusion of liability Regarding StillStupid: The use you make of the guides, tips and downloads that you listed on this web site or on another website to which I refer is entirely at your own risk. In no way can I be held liable for damage or consequential damages of any kind, which occurs as a result of that use.