I am making a installer for my program and I need to add a custom context menu action **only **to a certain mime type.
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.
- 4,066
- 4
- 47
- 106