I need to associate different file extensions with different apps for opening the files.
There are many many different types of text files, the contents are all essentially plain text, but they have different purposes and need to be opened in different apps.
It isn't reasonable in this case to expect the OS to correctly analyse the file when it may be something obscure and there are probably hundreds of different types of text files
In any case I want it to take my word for the type of file it is and rely on the extension rather than attempt a file analysis.
Specifically I want to associate the extension .scad with Openscad (which I run from an appimage) but not affect any other plain text files with no extension or different extensions.
If I change a .scad file in properties to open with Openscad as default then ALL plain text files attempt to open with Openscad from then on.
Similarly I want to associate whatever other extensions with specific apps even when the contents are all just plain text.
I have looked in ~/.config/mimeapps.list but I have not had any success editing that manually and I can't find a guide to the syntax.
The whole issue seems very confused between trusting a file extension to identify the file type and analyzing the file. I want it to rely on the extension by preference and only revert to contents analysis if there is no extension ( or maybe if it is is obviously incorrect such as a binary file with a .txt suffix)
I'm using Mint 19 Cinnamon
File extension associations with applications.
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
-
- Level 1
- Posts: 36
- Joined: Sat Dec 08, 2018 12:32 pm
File extension associations with applications.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: File extension associations with applications.
"Confused" is exactly right. The mime implementation is a complicated mess.halfshavedyaks wrote: ⤴Sat Dec 08, 2018 12:47 pmThe whole issue seems very confused between trusting a file extension to identify the file type and analyzing the file.
That would be too easy.I want it to rely on the extension by preference and only revert to contents analysis if there is no extension ( or maybe if it is is obviously incorrect such as a binary file with a .txt suffix)
I think you need to create a new "mime type", like text/scad; here are some amazingly poorly written instructions:
https://help.ubuntu.com/community/AddingMimeTypes
About half-way down ("Another way to add a MIME Type") it says the instructions up to that point don't work. They didn't work for me, so ignore the top half.
And you're in luck - he's adding the "scad" file type!
Edit: I tried the "Another way" and it didn't work either; the " update-mime-database" command deletes the scad.xml file.
This worked:
In the file
Code: Select all
/usr/share/mime/packages/freedesktop.org.xml
Code: Select all
#NEW 1
<mime-type type="application/scad">
<comment>Scad</comment>
<acronym>Scad</acronym>
<expanded-acronym>Scad</expanded-acronym>
<sub-class-of type="text/plain"/>
<glob pattern="*.scad"/>
</mime-type>
#NEW 2
Then run
Code: Select all
sudo update-mime-database /usr/share/mime
aa.scad
opens with abiword and aa.txt
opens with leafpad by default (just double-click)Free advice: make a backup copy of freedesktop.org.xml before you edit it!
More free advice:
I made the association with aa.scad by
file-browser->rt-click->open with (choose, e.g. abiword) -> set as default
, and in
Code: Select all
.config/mimeapps.list
Code: Select all
application/scad=abiword.desktop;
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Your data and OS are backed up....right?
Re: File extension associations with applications.
I think the second part of that ubuntu "help" might work - IF YOU PUT THE XML FILE IN
/usr/share/mime/packages
and NOT where they said to:
/usr/share/mime/application,
where it will get silently erased (the files there say "automatically generated, don't edit")
/usr/share/mime/packages
and NOT where they said to:
/usr/share/mime/application,
where it will get silently erased (the files there say "automatically generated, don't edit")
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Your data and OS are backed up....right?
-
- Level 1
- Posts: 36
- Joined: Sat Dec 08, 2018 12:32 pm
Re: File extension associations with applications.
wow thanks - your method worked. (I haven't looked at the link to the ubuntu help)
I just added the definition you gave at the end of the freedesktop file so I can find it again.
there's 40k lines in my freedesktop file, much of it much more niche than openscad and with support for loads of languages I will never use.
seems like some optimisation might be in order.
when I updated I got this:
not sure what that is supposed to mean, but the file association now seems to work and I assume I can use the same process for other file types.
I just added the definition you gave at the end of the freedesktop file so I can find it again.
there's 40k lines in my freedesktop file, much of it much more niche than openscad and with support for loads of languages I will never use.
seems like some optimisation might be in order.
when I updated I got this:
Code: Select all
sudo update-mime-database /usr/share/mime
Unknown media type in type 'all/all'
Unknown media type in type 'all/allfiles'