Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2300  / 2 Years ago, tue, july 26, 2022, 4:08:13

I need to change the menu items present in the Nautilus File Manager. I am open to getting my hands dirty in Python or anything else for that matter.
I would like add or remove menu items from the context menu in Nautilus. Any help regarding this will be very helpful.



Note:




  1. I am not looking to going to any other file manager for this reason.

  2. I am not talking about Nautilus scripts either. I would like to know how the menu item called 'Scripts' was created in the first place.


More From » gnome

 Answers
5

To add menu items to can write a Nautilus extension, like



from gi.repository import Nautilus, GObject

class MyItemExtension(GObject.GObject, Nautilus.MenuProvider):
def get_file_items(self, window, files):
menuitem = Nautilus.MenuItem(name='MyItem::SomeItem',
label='My Item',
tip='my own item',
icon='')

menuitem.connect('activate', self.on_menu_item_clicked, files)
return menuitem,

def on_menu_item_clicked(self, item, files):
print [f.get_name() for f in files]


Save this into something like /usr/share/nautilus-python/extensions/myitem.py, install the package python-nautilus and restart Nautilus, for example by running nautilus -q; sleep 2; nautilus. Now you should see a new item "My Item" if you rightclick a file.



As far as I know there is no documented way to remove menu items.



The see API reference for some more information.


[#27162] Wednesday, July 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iedncommon

Total Points: 200
Total Questions: 95
Total Answers: 132

Location: Tonga
Member since Mon, Aug 2, 2021
3 Years ago
iedncommon questions
Sat, Jun 4, 22, 18:20, 2 Years ago
Mon, Apr 4, 22, 08:10, 2 Years ago
Tue, Jul 6, 21, 15:11, 3 Years ago
;