Score:0

File Association on Ubuntu 20.04 not working

al flag

I m trying to launch my application using xdg-open myFile.axsd. This is my StartupLinux.desktop file:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=true
MimeType=application/x-demo
Name=StartupLinux
Exec=/home/<user>/MyWorkspace/StartupLinux %f

This is my application-x-demo.xml file

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-demo">
    <comment>new mime type</comment>
    <glob pattern="*.axsd"/>
  </mime-type>
</mime-info>

If I run the command:

gio mime application/x-demo

... I get that my application is the default application for the mime type. Command output:

Default application for “application/x-demo”: StartupLinux.desktop
Registered applications:
        StartupLinux.desktop
Recommended applications:
        StartupLinux.desktop

The problem is, If I run the command:

gio info myFile.axsd | grep "standard::content-type"

Command output:

standard::content-type: text/plain

The expected output was application/x-demo but I m getting it as text/plain, and a default text editor opens up instead of my app. I have followed this link for the file association.

Note: StartupLinux is a Gui Application

Any help here?

Score:0
cn flag

For a .desktop launcher to be able to be associated with a file, the command on the Exec= must include a placeholder for a file name, i.e., one of the %f, %u, %F or %U field codes.

Vipul Gupta avatar
al flag
I have added the field code, still it does not work.@vanadium
vanadium avatar
cn flag
Try associating the file type with the file manager (right-click - properties)
Vipul Gupta avatar
al flag
yes, but that will associate the text/plain mimetype with my application. But I want my mimetype/extension to be associated with my application
Score:0
cn flag

Besides the suggestion at @vanadium's answer, please check that you have done the following:

  • Put your application-x-demo.xml file into $HOME/.local/share/mime/packages directory. You will have to create that directory if it does not exist:
$ mkdir -p $HOME/.local/share/mime/packages/
  • After that, run the following two commands:
$ update-mime-database ~/.local/share/mime
$ update-desktop-database ~/.local/share/applications

Obviously, this configuration is for the current user only.

For more information you can look at add a custom MIME type for individual users.

Vipul Gupta avatar
al flag
tried this, still my application does not open up.
FedKad avatar
cn flag
I don't know about the `gio` thing you mentioned in the second part of your question, but creating the `$HOME/.local/share/applications/StartupLinux.desktop` and `$HOME/.local/share/mime/packages/application-x-demo.xml` files and running the above-mentioned two commands are something that I have used before. Please, check the syntax of your files once more (in my desktop file it is `Version=1.1` for example) and try to log out / log in. Note that these files normally do not have the executable permission bit set; I normally `chmod 644` them.
Vipul Gupta avatar
al flag
It's working now. I was trying to open an empty .axsd file which which was resulting in the default text editor to open. After adding some content to the file and then opening it using xdg-open results in my app to open and also the mimetype is now changed from text/plain to application/x-demo. Thanks for the help!
FedKad avatar
cn flag
Please, accept and/or upvote any answer that helps you, so that others with similar problems can benefit also... @VipulGupta
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.