For those looking for setting an application association for file extensions, NOT a mimetype:
Apparently, Ubuntu / Linux keeps this indirectly:
- file extension -> MIME types
- MIME type -> application(s) to open
- Applications -> list of compatible MIME types
For Ubuntu (18.x), these are described in:
file extension -> MIME types
This is in files in /usr/share/mime/packages/
.
E.g.:
cat <<EOF | sudo tee /usr/share/mime/packages/staruml.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/staruml-project">
<comment>StarUML project</comment>
<glob pattern="*.MDJ"/>
<glob pattern="*.mdj"/>
</mime-type>
</mime-info>
EOF
MIME type -> application(s) to open
This is driven by ~/.local/share/applications/mimeapps.list
and detailed the other answers.
[Default Applications]
echo 'application/staruml-project=staruml.desktop' >> ~/.local/share/applications/mimeapps.list
## Or, for global:
echo 'application/staruml-project=staruml.desktop' | sudo tee -a /usr/share/applications/mimeapps.list
Applications -> list of compatible MIME types
This is driven by the .desktop
files in /usr/share/applications/
. That file can contain a MimeType=
entry with semicolon-separated list of MIME types. For instance, the EOG app has: MimeType=image/bmp;image/gif;image/jpeg;image/jpg;...
etc.
cat <<EOF | sudo tee /usr/share/applications/staruml.desktop
[Desktop Entry]
Name=StarUML
Comment=StarUML
GenericName=StarUML
Exec=/sw/prog/StarUML/StarUML-3.1.0-x86_64.AppImage %U
Icon=/sw/prog/StarUML/staruml.png
Type=Application
StartupNotify=false
Categories=Development;Programming;Modeling;UML
MimeType=application/staruml-project;
EOF
This makes it a full circle. The changes take effect after running
sudo update-mime-database /usr/share/mime
and, for icons,
sudo gtk-update-icon-cache /usr/share/icons/gnome -f
Or, it may need you to logout/login.
Then, you should be able to see this:
$ mimetype .mdj
.mdj: application/staruml-project
Reference: https://coderwall.com/p/qjda2q/create-new-mime-type-and-assign-an-icon-to-it-in-ubuntu