Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to know how I can add action when the user right-clicks on specific MIME-types or folders without the use of nautilus-actions.

I would be happy if this was possible using Nautilus Scripts as well, but I want them to show up only at specific mime types.

I believe it is possible: Ubuntu One does it.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use Nautilus extension API for that. In particular I recommend Nautilus-Python.

Here's a simple example that adds a context menu item for MIME type text/plain:

from gi.repository import Nautilus, GObject

class ExampleMenuProvider(GObject.GObject, Nautilus.MenuProvider):
    def activate(self, menu, files):
        print 'activated' # do something

    def get_file_items(self, window, files):
        if len(files) != 1 or files[0].get_mime_type() != 'text/plain': return
        item = Nautilus.MenuItem(
            name='SimpleMenuExtension::Do_Something', label='Do Something')
        item.connect('activate', self.activate, files)
        return [item]

You'll need to install python-nautilus and gir1.2-gconf-2.0 packages and place the above Python script in ~/.local/share/nautilus-python/extensions/.

share|improve this answer
    
thanks! That is very useful! Is there something for C/C++ ? On your link says something about C but... –  hakermania Aug 1 '12 at 16:40
    
@hakermania: There is a C API documented in developer.gnome.org/libnautilus-extension/stable –  vitaut Aug 1 '12 at 17:16
    
Thanks! I now have to learn it –  hakermania Aug 1 '12 at 17:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.