LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Associating file extensions with separate programs for XML files. (https://www.linuxquestions.org/questions/linux-newbie-8/associating-file-extensions-with-separate-programs-for-xml-files-4175675304/)

JJBlige 05-15-2020 07:19 AM

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?

Many thanks in advance!

sevendogsbsd 05-15-2020 07:29 AM

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.

JJBlige 05-15-2020 07:37 AM

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.

wpeckham 05-15-2020 07:44 AM

Quote:

Originally Posted by JJBlige (Post 6123448)
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.

JJBlige 05-15-2020 08:06 AM

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?

Many thanks

sevendogsbsd 05-15-2020 08:21 AM

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.

wpeckham 05-15-2020 07:59 PM

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.

shruggy 05-16-2020 05:25 AM

Quote:

Originally Posted by sevendogsbsd (Post 6123482)
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.

@OP. See xdg-mime(1).

ondoho 05-16-2020 05:34 AM

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.

shruggy 05-16-2020 06:04 AM

Quote:

Originally Posted by ondoho (Post 6123820)
I don't know exactly how

There's an example at the end of xdg-mime manual page I linked above.

ondoho 05-16-2020 10:05 AM

^ yeah I saw an XML file much like that in my ~/.local/share/mime. The glob pattern would be the key for the extension.

JJBlige 05-17-2020 05:58 AM

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.


All times are GMT -5. The time now is 01:44 PM.