LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-15-2020, 07:19 AM   #1
JJBlige
LQ Newbie
 
Registered: May 2020
Location: NW-Europe
Distribution: Linux Mint
Posts: 6

Rep: Reputation: Disabled
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!
 
Old 05-15-2020, 07:29 AM   #2
sevendogsbsd
Senior Member
 
Registered: Sep 2017
Distribution: FreeBSD
Posts: 2,252

Rep: Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011
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.
 
Old 05-15-2020, 07:37 AM   #3
JJBlige
LQ Newbie
 
Registered: May 2020
Location: NW-Europe
Distribution: Linux Mint
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
Old 05-15-2020, 07:44 AM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,685

Rep: Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714
Quote:
Originally Posted by JJBlige View Post
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.
 
1 members found this post helpful.
Old 05-15-2020, 08:06 AM   #5
JJBlige
LQ Newbie
 
Registered: May 2020
Location: NW-Europe
Distribution: Linux Mint
Posts: 6

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-15-2020, 08:21 AM   #6
sevendogsbsd
Senior Member
 
Registered: Sep 2017
Distribution: FreeBSD
Posts: 2,252

Rep: Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011
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.
 
Old 05-15-2020, 07:59 PM   #7
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,685

Rep: Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714Reputation: 2714
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.
 
Old 05-16-2020, 05:25 AM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by sevendogsbsd View Post
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).
 
Old 05-16-2020, 05:34 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
Old 05-16-2020, 06:04 AM   #10
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
I don't know exactly how
There's an example at the end of xdg-mime manual page I linked above.

Last edited by shruggy; 05-16-2020 at 06:07 AM.
 
Old 05-16-2020, 10:05 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
^ yeah I saw an XML file much like that in my ~/.local/share/mime. The glob pattern would be the key for the extension.
 
Old 05-17-2020, 05:58 AM   #12
JJBlige
LQ Newbie
 
Registered: May 2020
Location: NW-Europe
Distribution: Linux Mint
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
libvirt: post virt-clone, unchanged values in resulting XML file from original XML file CptSupermrkt Linux - Virtualization and Cloud 1 04-14-2016 08:20 AM
Encoding separate audio channels to separate files omnio Linux - Software 0 06-01-2007 07:46 AM
Looking for a tool to auto crop and separate images in to separate files.. mlsfit Linux - Software 2 08-06-2006 03:13 PM
Associating Files with Programs in Gnome Cinematography Linux - Software 2 05-25-2005 06:40 PM
Associating Torrent Files JonBrant Mandriva 2 07-21-2004 10:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration