I am making a installer for my program and I need to add a custom context menu action **only **to a certain mime type.
-
Hello. There is not such version of Ubuntu called latest. There are at least 2 versions that can be referred to as latest. – David Mar 30 '22 at 15:57
-
https://help.ubuntu.com/community/AddingMimeTypes – vanadium Mar 30 '22 at 15:59
-
Sorry, I meant ubuntu verson 21.10. @vanadium Also, as stated, I have a mime type, I just need to add a custom context menu action to that certain mime type. – Markian Mar 30 '22 at 20:29
-
Not sure if that is generally possible. File managers can set default associations, but implementing your custom right-click menu item will depend on the specific file manager. For nautilus, you can use Python extensions. You probably want to edit your question and indicate more specifically and concisely what you want to achieve. Currently, your information about "a custom program" and "a custom content menu action" and "a certain mime type" can only lead to "an answer", if any. – vanadium Mar 31 '22 at 07:30
-
Does this answer your question? How do I customize the context menu in Nautilus? – cipricus Jan 30 '23 at 07:22
1 Answers
It's odd you haven't got an answer to this basic question, although I imagine that in the meantime you have found it yourself. I will provide an answer based on my current settings for Kubuntu and Dolphin, but you can extrapolate them to Gnome/Nautilus, Xfce/Thunar etc. This involves the use of .desktop
files located in different folders depending on the file manager, but in all cases the specific mime type is determined by a line that starts with MimeType=
.
First, you have to know the correct mime type. To get that for any file, why not create a context menu?
A generic mime type setting that would give you a menu action for any file should be of the form
MimeType=application/octet-stream;
The command itself for showing the mime type of the selected file could be like
file --mime-type -b "%u"
For example, in Kubuntu, I have the file ~/.local/share/kservices5/ServiceMenus/CheckMimeType.desktop
of the form
[Desktop Action FileMimeType]
Exec=bash -c 'type=$(file --mime-type -b "%u"); kdialog --title "Checking Mimetype" --msgbox "MimeType: $type";';
Icon=preferences-desktop-filetype-association
Name=Check MimeType
[Desktop Entry]
Actions=FileMimeType
Icon=auto-type
MimeType=application/octet-stream;
ServiceTypes=KonqPopupMenu/Plugin
Type=Service
(But that's for KDE, in Gnome with Nautilus the file is different and has a different location. As you haven't provided more details on what programs you use, and in any case, I can only direct you to answers already present on askubuntu, to which I added the links above. This question would probably show to be a duplicate of those if you add more details to it.)
In the same way, you can apply your command to your specific mime type.

- 3,444
- 2
- 34
- 85