How to associate file extension (not file type) for a particular application?

Solution 1:

Rename the file you have as _anything_.task (where _anything_ is something suitably descriptive.)

First you need to create an XML file with the extension information in it. (If you wish, copy the text below into a new text file and save it as task.xml.)

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/taskcouch">
<comment>TaskCoach File</comment>
<comment xml:lang="bg">Taskcoach</comment>
    <comment xml:lang="cs">Taskcoach</comment>
    <comment xml:lang="de">Taskcoach</comment>
    <comment xml:lang="es">Taskcoach</comment>
    <comment xml:lang="eu">Taskcoach</comment>
    <comment xml:lang="hu">Taskcoach</comment>
    <comment xml:lang="it">Taskcoach</comment>
    <comment xml:lang="ko">Taskcoach</comment>
    <comment xml:lang="nb">Taskcoach</comment>
    <comment xml:lang="nl">Taskcoach</comment>
    <comment xml:lang="nn">Taskcoach</comment>
    <comment xml:lang="sv">Taskcoach</comment>
    <comment xml:lang="uk">Taskcoach</comment>
    <comment xml:lang="vi">Taskcoach</comment>
<glob pattern="*.task"/>
<alias type="application/taskcoach"/>
</mime-type>
</mime-info>

You now need to save or copy this new file into the directory

  • ~/.local/share/mime/packages for a per-user file association or
  • /usr/share/mime/packages for a system-wide file association.

Once that is done, run

update-mime-database [MIME-DIRECTORY]

where [MIME-DIRECTORY] is the previously chosen directory minus the /packages suffix. (Use sudo for the system-wide association.)

Now, open your file manager and right-click on anything.task and select taskcoach as the default program with the open with option in the context menu.

Job done. All .task files will now open with taskcoach!

Solution 2:

The file opens in TaskCoach, but any other .XML file gets opened with TaskCoach too!

That happens because they’re all the same MIME type (application/xml).

If you want TaskCoach files to be treated differently from other XML files, you need to configure a new MIME type for them.

I’ve never done that before, but it looks like Gnome has pretty good documentation on how to do it: Add a custom MIME type for all users / individual users.