2

I made a Qt application, let's call it "alpha," that opens and generates .zip files. So basically, my files created by the app have the extension .alpha but they are basically .zip files. How do I associate .alpha files with my "alpha" application? Currently, by default, the .alpha files open with archive manager (because the system sees them as .zip files).

I looked at many possible solutions, with no success. I have tried the below methods:

  1. I created a alpha.xml file in /usr/share/mime/packages

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
        <mime-type type="application/alpha">
            <comment>ALPHA File</comment>
            <glob pattern="*.alpha"/>
        </mime-type>
    </mime-info>
    

    Now when I click abc.alpha file, I get an error saying:

    Could not display "abc.alpha". There is no application installed for "ALPHA File" files.
    
  2. I edited the /etc/mime.types file to include the following line:

    application/alpha                zip
    
  3. I created the file alpha.desktop - this works fine, as ALPHA is now shown in "open with other applications." However I still can't double click a .alpha file to open it in my program.

How do I solve this? Thanks in advance.

1 Answer 1

3

From Archlinux default applications:

  1. Create your xml file in ~/.local/share/mime/packages (I guess that /usr/share/mime/packages is also fine, but didn't test it)

    mkdir -p ~/.local/share/mime/packages
    touch ~/.local/share/mime/packages/application-alpha.xml
    
  2. Edit application-alpha.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
        <mime-type type="application/alpha">
            <comment>alpha file</comment>
            <glob-deleteall/>
            <glob pattern="*.alpha"/>
        </mime-type>
    </mime-info>
    
  3. Now create the desktop file ~/.local/share/applications/alpha.desktop:

    [Desktop Entry]
    Name=Alpha
    Exec=/PATH/TO/YOUR/alpha
    MimeType=application/alpha
    Terminal=false
    Type=Application
    

    add the right exec path to your alpha application, and if this a console app change Terminal to true.

  4. Now update the applications and mime database with:

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

Now if you double click your abc.alpha file /PATH/TO/YOUR/alpha app should open your file.

4
  • Worked like a charm! Thanks. I had missed out adding "MimeType=application/alpha" in the alpha.desktop file
    – akashrajkn
    Mar 18, 2016 at 15:01
  • what does this line in the application-alpha.xml file do? <glob-deleteall/>
    – akashrajkn
    Mar 18, 2016 at 15:02
  • 1
    @akashrajkn glob-deleteall indicates that patterns from previously parsed directories must be discarded. The patterns defined in current file are used instead. From here. So you probably can also delete this line. Mar 18, 2016 at 15:06
  • where should I place the image.svg for it to be used as an icon? I tried putting it in /usr/share/icons/gnome/scalable/mimetypes, but the icon is not being shown
    – akashrajkn
    Mar 18, 2016 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.