Score:1

How to associate an AppImage to a mime type by default in Ubuntu 22.04

gr flag

I have seen this, this, and this.

Everyone talks about how to search for the app and launch it from a shortcut (instead of running it as an executable).

However, nobody talks about associating an AppImage with a mime type.

My goal is to click on a .stl file and open it with a default program that only ships as AppImage for Ubuntu/Linux.

As mentioned in the linked posts, this program already appears in the search because I integrated it by adding a .desktop launcher.

Score:1
us flag

As you've mentioned that you've already looked at how to create a desktop launcher for your AppImage, I'm going to skip that part.

You're looking to edit the .desktop launcher and change what mime types are associated with it.

FWIW, this is not specifically for AppImages; this is how freedesktop desktop launchers work

I don't know what program you're referring to, but I'll use the following launcher as an example.

The launcher below is for a text editor called Nota. We're interested in the line MimeType=; as you can see, it reads MimeType=text/plain; which means that Nota is associated with any text file.

[Desktop Action FirejailProfile]
Exec=firejail --env=DESKTOPINTEGRATION=appimaged --private --appimage /Applications/nota
Name=Run without sandbox profile
TryExec=firejail

[Desktop Entry]
Categories=Qt;KDE;Utility;TextEditor;
Comment[es_MX]=Text editor
Comment=Text editor
Exec=/home/uri/Applications/nota-v2.2.0-stable-amd64.AppImage
GenericName[es_MX]=Text Editor
GenericName=Text Editor
Icon=nota
Keywords=text;editor;
MimeType=text/plain;
Name[es_MX]=Nota
Name=Nota
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
TryExec=/Applications/nota
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

To know what to put in that line for the desktop launcher that you've created you can do the following.

file -b --mime-type file.stl

This command will tell you what the mime type is. For example, the output could be application/sla for your .stl files.

So, the line in your desktop launcher would read MimeType=application/sla; and it so the desktop launcher would be registered to launch whatever is in Exec= and open that mime type.


Alternatively, you probably want to extract the upstream desktop launcher inside the AppImage and edit it accordingly, as I described here.


Next, edit ~/.config/mimeapps.list, and append:

application/sla=YourApp.desktop;

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.