This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Tools & Utilities

Extending Nautilus context menus with Nautilus-actions

By Shashank Sharma on October 22, 2007 (9:00:00 AM)

Share    Print    Comments   

There are literally dozens of plugins and extensions for Nautilus, the default file manager on the GNOME desktop environment, but there is just one that allows you to customize the Nautilus context menu items. The Nautilus-actions extension enables you to add customized entries to the context menu such that, when you right-click a file, the context menu will show options specific to that file.

 Ubuntu and Fedora users can use apt-get and yum respectively to install Nautilus-actions. The nautilus-image-converter and nautilus-open-terminal extensions we discussed recently were both created using the Nautilus-actions extension, so let's see how Nautilus-actions works.

On my Fedora 7 machine, the Nautilus Actions Configuration tool is available under System -> Preferences -> Look and Feel -> Nautilus Actions Configuration. This tool allows you to create new context menu items. To create a new action (context menu item), click the Add button. This brings up the Add a New Action dialog box. You can fill in the name of the menu item (label), a description of what it does (tooltip), and path and other parameters under the Menu Item & Action tab. The Conditions tab lists options that allow you to control the file types to which your custom action applies. Various advanced options are listed under the Advanced Conditions tab.

To begin, let's create a simple bash script that, when provided with a file, prints out every URL in that file along with five lines above and below the link in a new file. We will next create a context menu item such that right-clicking on any text file will give us an option to execute the script on the file. Here's the script:

#!/bin/sh

FILE=$1

grep -F -A5 -B5 http $FILE > ~/Desktop/linksfile.txt

I've named the script script.sh and saved it on my Desktop. This script accepts a filename, and using grep prints out every line in which http appears, along with five lines above and below it, into a new files called linksfile.txt. Next we need to create a context menu item using the Nautilus Actions Configuration tool. Click on Add in the Nautilus Action configuration window, and in the Add a New Action dialog box, fill in the field like this:</p.

Label: Print the URLs
Tooltip: Print five lines before and after every URL
Path: /home/yourdirectory/Desktop/script.sh
Parameters: %M

The actual text you want to appear in the context menu should go into the label field. The message in tooltip text field is displayed when a user hovers the mouse over the context menu entry. You can click the Legends button for a description of all the parameters. %M gives a complete path of the selected file. It is this path that is stored in the FILE variable in our script.

Next, click on the Conditions tab. If you wish to run the script only on text files, write *.txt in the Filename field. Since the script can't operate on Folders, click on the Only Files radio button. Finally, click OK and close the Nautilus Actions Configuration tool. Now, when you right-click on text files, you'll see the Print the URLs option, and clicking on it will create a file linksfile.txt on your Desktop.

The purpose of this very mundane script is to show you what Nautilus-actions can do. There are several other configurations available on the extension's official Web site. Simply download the configuration files to your system, open the Nautilus Actions Configuration tool, and click Import/Export. In the Import/Export Settings dialog box, write the full path to where you saved the configuration file, and click on the Automatic radio button under Type of Configuration. The configuration will be added when you click OK.

Nautilus-actions's ability to execute script on files, execute programs with various command options, and operate on multiple files at once makes it exceptionally useful.

Every Monday we highlight a different extension, plugin, or add-on. Write an article of less than 1,000 words telling us about one that you use and how it makes your work easier, along with tips for getting the most out of it. If we publish it, we'll pay you $100. (Send us a query first to be sure we haven't already published a story on your chosen topic recently or have one in hand.)

Shashank Sharma specializes in writing about free and open source software for new users and moderates the Linux.com forum boards. He is the coauthor of Beginning Fedora, published by Apress.

Share    Print    Comments   

Comments

on Extending Nautilus context menus with Nautilus-actions

Note: Comments are owned by the poster. We are not responsible for their content.

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 145.253.187.66] on October 22, 2007 10:23 AM
I doubt you can detect URL by greping for "http". Please do a little research on URLs.

#

Re: Extending Nautilus context menus with Nautilus-actions

Posted by: Shashank Sharma on October 22, 2007 10:35 AM
I appreciate what you said. My purpose was not to create a foolproof script to print all the URLs. By grepping for http only those URLs will be printed where the person gives the complete URL (http://linuxlala.net) which means if someone posts linuxlala.net it won't be printed. One could easily create a grep expression to print out the URLs but that's not the focus of this article.

#

shark atop an elephant - next big app?

Posted by: Anonymous [ip: 66.122.165.195] on October 22, 2007 09:59 PM
I would like to see a menu item on a brouser tool bar say under tools that mite say ream or paper or pad. When clicked on it would turn the brouser page into a blank ream of paper that could be navigated using a 4 directional fwd, back, up, down arrows. At first it would accept text example: Type title on the first page arrow down to next page and type table of contents arrow down to begin first page then arrow down to next page etc.. On any given page or using a fwd, or back arrow after clicking on a highlighted table of contents item, a sibling page is available to begin that topic. Revisions to the page could be made using another sibling. Siblings would be a circular queue allowing one to set the virsion number for banch traversal top to bottom of the prefered eddition. Widgits could be added to accomodate the following; Drag and drop any content pictures vidio audio onto a given brouser page. The entire tree is placed in home unless otherwise specified and given an index number unless titled. On could provide features that allow the mouse to size boxes to place text images or vidio into as a format editing feature.- Once this functionality is in place mash up type applications could collect local resturant menues. Since the application is allready formated as a brouser page one could send the labled tree to a host as a web site. Any assortment of collections aswell features that dynamicaly update content through rss feeds or links could be used to list videos and sort them by use and stare time as the most popular using linklist type sorting between pages. Maps could be colected that drill down as one traverses the tree to show events, cousine, topic identified content.

#

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 170.160.9.3] on October 22, 2007 10:42 PM
Okay, so I have configured a XML configuration file for Nautilus as per your instruction above - Whats a good way to get it (the GConf Schema) into the GConf database on the System level so all users can access the action? My efforts at this so far have been less than perfect - even trashing the GConf DB in more than one occasion.....

#

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 147.163.1.235] on October 23, 2007 08:21 AM
I would understand how to copy selected paths (dirname, filename or fullpath) to clipboard

#

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 170.160.9.3] on October 23, 2007 08:14 PM
loading it instantially is not a problem, but it would be nice to have a clean method for creating these schemas and permanently setting them in nautilus for all the users on a system. My experiences with NACT to date have not shown this to be very straight forward. I was kinda hoping that you might have a more elegant solution....

#

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 83.8.219.218] on October 24, 2007 12:04 AM
Thanks for another very interesting article. Keep up the good work. Regards
<a href="http://www.profesjonalna-reklama.pl" target="_blank">Pozycjonowanie</a> <a href="http://www.topblogposts.info" title="Blog">Tom</a>

#

good news

Posted by: Jen on October 31, 2007 02:02 AM
I found http://www.boxsweeper.com has a lot of movies anime music and games!This website is quite great! And it's free for you to streaming and download! Check it out and enjoy it! It will save you much time and money! Don't forgot to thanks me........ha ha

#

Extending Nautilus context menus with Nautilus-actions

Posted by: Anonymous [ip: 89.60.217.10] on November 14, 2007 08:57 AM
I agree, really good news, thanks for sharing.
<a href="http://www.yellobook.eu" title="yellowpages">yellowpages</a>

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya