[SOLVED] Associating file extensions with separate programs for XML files.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Associating file extensions with separate programs for XML files.
Hello! I have two files that are both XML files, according to the properties tab. One is named one.tks, the other two.pvd. I've tried associating both files to different programs, but since they are both XML files changing the default program for one.tks will also change the default program for two.pvd. How do I associate the two different extensions (tks and pvd) with two separate programs?
It depends entirely on your distro's desktop environment or file manager. Most file managers have a way of setting one default, then have another option for "open with" or something to that effect. You can't set 2 defaults.
I'm using Linux Mint 19 Cinnamon. So the filename extensions used here can not be associated with different programs, because their underlying filetype is the same? I was hoping their would be some backend fix.
Hello! I have two files that are both XML files, according to the properties tab. One is named one.tks, the other two.pvd. I've tried associating both files to different programs, but since they are both XML files changing the default program for one.tks will also change the default program for two.pvd. How do I associate the two different extensions (tks and pvd) with two separate programs?
Many thanks in advance!
Why? What are you trying to achieve?
Linux does not, in general, pay any more attention to Microsoft style "file extensions" than it does to any other part of the file name, but it does pay attention to the file type as detected in the first few bytes of the content. If you understand and use that information, a kludge may be possible.
I'm currently right clicking every file and specifying which program should open it. I know for instance that every file with the *.msh extension should be opened with GMSH, but Linux recognizes it to be a xml file type and opens it with gedit. I have loads more of such files that are clearly labelled through Microsoft style extensions.
Is there a similiar way to have a *.msh file automatically associate with a program? Can I introduce a new file-type xml/msh somewhere? Should I add a line that specifies which program to use in the file data?
They are not associated with extensions, they are associated as wpeckam stated via mime type. Perhaps the file manager in cinnamon has no way to "open with" - I have never used cinnamon so can't speak to the "Nemo" file manager. You could eliminate the file extensions entirely and the behavior would be the same.
Has anyone ever tries a method of adding a #! line to an xml file to force a particular program to load it by default?
I have never tried, but it seems a decent concept to research.
Perhaps the file manager in cinnamon has no way to "open with"
I think it's the other way 'round: each application specifies in its .desktop file with MimeType key which file types it wants to handle. The file manager decides then what application is the preferable handler for the given MIME type or asks the user if it cannot decide on its own.
I think what you want is possible with mime types - they _can_ take file extensions into account.
I don't know exactly how, but look at e.g. ~/.config/mimeapps.list, ~/.local/share/applications/mimeinfo.cache, and the contents of ~/.local/share/mime.
FWIW, I right-click files more often than double-click.
Thanks everyone! This helped a bunch.
I registered all extension that were unrecognised in my desktop environment to new Mime types using xdg-mime. I then coupled the new Mime types to existing programs using .desktop files. I'm marking this as solved.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.