3

I've created and registered some shared-mime-info files for custom file types. For example, in

~/.local/share/mime/packages

I've added files like

x-myokit.xml

containing a mime type description, for example

<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="text/x-myokit">
    <comment xml:lang="en">Myokit model definition</comment>
    <glob pattern="*.mmt"/>
  </mime-type>
</mime-info>

Nautilus now recognises my files, but still displays the file type as "Unknown". How do I make it show something more useful in this column?

3

This was hardcoded in Nautilus as per the devs decision to only show basic type information in the Type column by default, so that sorting by type would group type families.
The basic types are defined in nautilus-file.c based on generic (symbolic) icon names1:

struct {
        const char *icon_name;
        const char *display_name;
} mime_type_map[] = {
    { "application-x-executable", N_("Program") },
    { "audio-x-generic", N_("Audio") },
    { "font-x-generic", N_("Font") },
    { "image-x-generic", N_("Image") },
    { "package-x-generic", N_("Archive") },
    { "text-html", N_("Markup") },
    { "text-x-generic", N_("Text") },
    { "text-x-generic-template", N_("Text") },
    { "text-x-script", N_("Program") },
    { "video-x-generic", N_("Video") },
    { "x-office-address-book", N_("Contacts") },
    { "x-office-calendar", N_("Calendar") },
    { "x-office-document", N_("Document") },
    { "x-office-presentation", N_("Presentation") },
    { "x-office-spreadsheet", N_("Spreadsheet") },
};

Types that do not fall in the above categories are shown as Unknown:

if (basic_type == NULL) {
    basic_type = g_strdup (_("Unknown"));

As a result, a file with mime type application/x-myokit (with a corresponding symbolic icon name application-x-generic) will be listed as Unknown in the Type column while a file with mime type text/x-myokit (with a corresponding symbolic icon name text-x-generic) will be listed as Text in the Type column (see also various system files like *.so files under /usr/lib or *.mo files in /usr/share/locale - they're all listed as Unknown but if you select one of them and hit Alt+Enter you get detailed, accurate information).


You can make Nautilus list something else if you use generic-icon name in your xml file. Though your options are limited to the above mentioned categories. So, e.g. if you wanted each of your *.mmt files to be listed as Program in the Type column you would edit your x-myokit.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
    <mime-type type="application/x-myokit">
        <comment>Myokit model definition</comment>
        <generic-icon name="text-x-script"/>
        <glob pattern="*.mmt"/>
    </mime-type>
</mime-info>

Don't forget to update the mime database with:

update-mime-database ~/.local/share/mime

If you need more useful informations you could enable/check the MIME type column in Nautilus preferences (or with dconf/gsettings: add mime_type to org.gnome.nautilus.list-view default-visible-columns).

1: run gio info -a standard::symbolic-icon file to see the corresponding symbolic icon names (on older setups replace gio info with gvfs-info)

1

I believe Nautilus gets the file description from the location /usr/share/applications. You could find more useful information from my other answer here. Particularly, this answer in Ask Ubuntu discusses how the file assosiciations are stored in detail.

The file manager (Nautilus, by default) uses the MIME type of a file to determine which program to open it with. When an application is installed, it can specify what MIME types it can open and the command to use to open the files in the .desktop file which is placed in /usr/share/applications. This is the file used for menus, desktop shortcuts, etc.

  • Thanks Ramesh. I've updated my answer to show I've already added a file letting nautilus determine the mime types. If I don't have any application registered and double-click, it says something like 'No application registered for files of type "Myokit model definition"' which shows that it reads and uses these mime type files. However, in the column "Type" it still shows something useless like "Unknown" or "text". My question is how to change this. – Michael Clerx Jan 6 '15 at 16:50
  • 1
    @MichaelClerx, ok. Let me check. I am not aware of this but will update the answer if I find any. – Ramesh Jan 6 '15 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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