Is it possible to associate a file with a program based on its extension and not its mime type?

I have been working on a VN a lot lately and so obviously I set the default program to open .rpy files to atom. The only problem is that .rpy files are also basic text files, so when I go to open a non-rpy file without thinking, it by default opens atom, not kate, which is slightly frustrating. I was just wondering if it was possible to seperate the .rpy extension and have atom be the default editor for .rpy, and kate be the default for the rest of the plain text mime type?

Hello @TheLastNarwhal :wink:

Sure… you need to find the correct mime type and put it in $HOME/.config/mimeapps.list

Could be possible that something like that is correct:

text/rpy=org.gnome.gedit.desktop;

https://wiki.archlinux.org/index.php/Default_applications

Thank you for your response and suggestion.

Unfortunately this didn’t seem to work. It completely ignored the modification and went about its business as usual. I believe the issue is that rpy files have the mime type ‘plain text’ and I can’t seem to distinguish the file extension from the mime type.

I looked over the link you sent and the mimeo bit seemed like it might work, but it also seemed like it could more or less break all my file associations… I don’t know, I’m a newbie, I’m not afraid of trying to work things out, but at the same time I don’t really want to spend hours troubleshooting something 'til it works, and then find out that I fixed one problem, but two more popped up in its place.

Do you have any other suggestions?

Hi and welcome to the Forum!

[Step 1]
In order to register a new MIME Type for the files with the .rpy extension for your user (it’s safer to do this for your user and not system-wide), create a new file called text-rpy.xml with this content:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="text/rpy">
    <comment>rpy MIME Type</comment>
    <glob pattern="*.rpy"/>
  </mime-type>
</mime-info>

Copy this file in the directory ~/.local/share/mime/packages/ (create this directory if it doesn’t already exist).

Open a terminal window and run this command:

update-mime-database ~/.local/share/mime

[Optional Step 2]
Copy the .desktop file of Atom to the ~/.local/share/applications/ directory (create this directory first if it doesn’t already exist):

cp /usr/share/applications/atom.desktop ~/.local/share/applications/

Open the ~/.local/share/applications/atom.desktop file with a text editor and add the new MIME Type in the line beginning with MimeType, so that it becomes similar to this:

MimeType=text/plain;text/rpy;

After that run this command in a terminal window:

update-desktop-database ~/.local/share/applications

This should register Atom as a program that can open the text/rpy MIME Type.

[Step 3]
Run the following command to set Atom as the default handler for the new MIME Type text/rpy.

xdg-mime default atom.desktop text/rpy

For all other plain text files (MIME Type text/plain) set Kate as the default handler that will open them:

xdg-mime default org.kde.kate.desktop text/plain
5 Likes

Thank you so much bill_t, this is the exact solution I was hoping for! Something that was simple enough that I could understand it, as well as a step by step guide for how to implement your suggestion. I really am quite grateful, and I’m glad I decided to create an account to ask this question instead of trying to go it alone, failing and then just grudgingly accepting the situation.

2 Likes

Hello again @bill_t, I have another question that I hope you’ll be able to solve. I was wondering if it was also possible to further distinguish between files of the same type? For example, I also have to edit rpa extensions, but some of the rpa files are text content - which I can and do edit with atom - and some are archives or zipped containers - which can’t be edited by atom for obviouse reasons. I have already created a mime type for rpa extensions following your example, but I was wondering if it was possible to only assign atom to the rpa extensions that contain text, and not the ones that are archives?

If this isn’t possible that’s okay, but it would be really cool if it were!

EDIT: Nevermind, ignore this question. I was being lazy. It’s better practice to just unarchive rpa files with rpatool and then edit the rpy file that pops out. Thank you for your time.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.