How to associate different file endings with different programs?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Joel
Level 1
Level 1
Posts: 33
Joined: Mon Aug 30, 2021 3:38 am

How to associate different file endings with different programs?

Post by Joel »

Just stumbled into another quirk.

When I try to open my QGIS project files, which are markup text files with the ending .qgs, it detects them as HTML files and tries to open them in Firefox. To open them correctly I have to right click --> Open with... and manually scroll down all the way to QGIS, because apparently it wouldn't ever consider to suggest that at the top.

So I set QGIS as the standard program to open them with. Now all my HTML files open with QGIS. .html, .htm, .qgs, the lot. Annoying, to say the least. How do I associate a specific file ending like .qgs, with a certain program like QGIS? I can't find anywhere to change it. And why is Linux Mint trying to be smart with the filetypes, instead of going by the file ending like Windows? I use 20.2, Cinnamon.
Last edited by LockBot on Wed May 24, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pjotr
Level 24
Level 24
Posts: 20142
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: How to associate different file endings with different programs?

Post by Pjotr »

Might be a Cinnamon bug. Try an in-place upgrade to Mint 20.3 and take it from there.

If that doesn't help: create a live USB with the iso of Mint 21 Cinnamon, boot from it and test in the live environment. When that does work as it should, consider a fresh clean installation of Mint 21.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
spamegg
Level 14
Level 14
Posts: 5117
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: How to associate different file endings with different programs?

Post by spamegg »

How do I associate a specific file ending like .qgs, with a certain program like QGIS? I can't find anywhere to change it.
Generally speaking you can't, it's extremely difficult and complicated on Linux. Because on Linux there are no file extensions. There are MIME types, but it's messy and complicated.
And why is Linux Mint trying to be smart with the filetypes, instead of going by the file ending like Windows?
On Linux, there are no file extensions. It just doesn't work like Windows. So when you see a file, say, book.pdf, the part .pdf is NOT a file extension. It's part of the filename. You could rename that to whatever you want, Linux will still see it as a PDF because it looks at the first few bits of the file header to determine the file type.

But Desktop Environments (such as Cinnamon) try to imitate Windows-like behavior, at least cosmetically. So this creates a lot of confusion for newcomers. When you use the "Open With..." then "Set as default" options, the system is actually changing the default application for the MIME type without telling you.

I'll explain the MIME type stuff below.
Now all my HTML files open with QGIS. .html, .htm, .qgs, the lot.
Yes, because the system sees the MIME types of those files as the same. You can see it with the xdg-mime command. Let's say you have the file myproject.qgs. Run this command in the folder where that file is:

Code: Select all

xdg-mime query filetype myproject.qgs
My guess is that it will say something like text/html.

This is because THERE IS NO FILE EXTENSION. .qgs means nothing. My guess is that the .qgs files are actually HTML files in disguise.

To make sure of this, I downloaded some sample .qgs data from here https://download.qgis.org/downloads/dat ... e_data.zip

I unzipped it and found a file relations.qgs. I opened that file in a NORMAL TEXT EDITOR, like Geany. And yes, it's an HTML file!

Code: Select all

<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.2.0-Valmiera">
    <title></title>
    <relations>
        <relation referencingLayer="airports20140502155725153" referencedLayer="regions20140502145258447" id="airport_region_fk" name="airport_regions">
            <fieldRef referencedField="ID" referencingField="fk_region"/>
        </relation>
    </relations>
 ...
Then I ran xdg-mime on that file...

Code: Select all

 ➜ xdg-mime query filetype relations.qgs
text/html
Yep! That's why the system determines the MIME type of your project files as HTML. So when you change the "default app for .qgs files", it's actually changing the "default app for the text/html MIME type".

There is a way to create your own custom MIME types, update the MIME database with it, create a custom default app entry for that type, and update the desktop database with it. But it would require a long and complicated tutorial to explain. I've done it once or twice, with mixed results. I don't fully understand it myself so I won't give instructions here.
User avatar
Joel
Level 1
Level 1
Posts: 33
Joined: Mon Aug 30, 2021 3:38 am

Re: How to associate different file endings with different programs?

Post by Joel »

spamegg wrote: Thu Nov 24, 2022 6:08 am Because on Linux there are no file extensions. There are MIME types
Ok, I figured it out. Apparently, QGIS does contain a MIME type specification file (https://github.com/qgis/QGIS/blob/maste ... s-mime.xml), but why my installation has been exempt from this blessed file remains a mystery. So I downloaded the file and installed it, by the instructions of a good fellow Minter (viewtopic.php?t=363837). Problem solved.

Although, I'm still curious why Linux has decided to walk this path. The big advantage of file endings is that it becomes so easy for anyone to change which program is associated with a file. This is the very reason that there are lots of file endings for different type of text files, which are in fact essentially not different, they are still text files. Conflicts such as the one between .html and .qgs files are bound to arise when file endings have no effect, and fixing it becomes much harder. Welp, it's hard trying to understand this world of Linux. Guess I'm learning at least.
User avatar
spamegg
Level 14
Level 14
Posts: 5117
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: How to associate different file endings with different programs?

Post by spamegg »

Although, I'm still curious why Linux has decided to walk this path.
Unix has been like that for decades. It's not something Linux "chose" on purpose. It's for historical reasons. It's just fundamentally different in how it works compared to Windows. It wasn't made with graphical user interfaces in mind. There are pros and cons to both approaches. (Relying on part of a file name brings other issues with it.)

Take my advice: never expect Linux to work like Windows, even in the most basic things. Expect everything to be completely different. I'm not defending Linux here (Linux sucks!), just saying that's how it is.

That tutorial is nice, I was about to make one myself! Glad someone else had it already. Although I'd consider it half finished. There is a second part, if the application you want to open those files is not already registered. By adding a .desktop file to ~/.local/share/applications for a specific application that you want, and then using update-desktop-database to have that application associated with that file type... I guess that can be done graphically. Anyway.
User avatar
Joel
Level 1
Level 1
Posts: 33
Joined: Mon Aug 30, 2021 3:38 am

Re: How to associate different file endings with different programs?

Post by Joel »

spamegg wrote: Thu Nov 24, 2022 9:58 am Take my advice: never expect Linux to work like Windows, even in the most basic things. Expect everything to be completely different. I'm not defending Linux here (Linux sucks!), just saying that's how it is.
Good advice. I'm not expecting Linux to be like Windows, but I'm expecting it to be... logical. But I guess it is in some sense, although I'm quite far from understanding just how yet :)
Locked

Return to “Software & Applications”