Manipulating file associations
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2016
    Location
    USA
    Posts
    35

    Manipulating file associations

    I have a few files that are considered "plain text document" files and as such, I have to use "Open with other application" in order to open them with different tools. In other words, because Linux has determined the files to be "plain text document" files, it apparently assumes I always want to open them with the same tool. I don't.

    The files have different extensions, so it seems possible that I could associate a different tool to each type, but I cannot figure out how to do that.

    For ex.
    I'd like to double-click on files with .txt extension and open them with some editor (say VIM)
    I'd like to double-click on files with .mike extension and open them with some other editor (say notepadqq)

  2. #2
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    2,971

    Re: Manipulating file associations

    Long ago I wrote myself a little howto file for this problem.

    How To Set Up File Associations

    The following method creates a custom mime type and file association manually. This is useful if your desktop does not have a mime type/file association editor installed. In this example, a fictional multimedia application 'foobar' will be associated with all *.foo files. This will only affect the current user.
    First, create the file ~/.local/share/mime/packages/application-x-foobar.xml:
    Code:
    $ mkdir -p ~/.local/share/mime/packages
    $ cd ~/.local/share/mime/packages
    $ touch application-x-foobar.xml
    Then edit ~/.local/share/mime/packages/application-x-foobar.xml and add this text:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
        <mime-type type="application/x-foobar">
            <comment>foo file</comment>
            <icon name="application-x-foobar"/>
            <glob-deleteall/>
            <glob pattern="*.foo"/>
        </mime-type>
    </mime-info>
    Note that you can use any icon, including one for another application.
    Next, edit or create the file ~/.local/share/applications/foobar.desktop to contain something like:
    Code:
    [Desktop Entry]
    Name=Foobar
    Exec=/usr/bin/foobar
    MimeType=application/x-foobar
    Icon=foobar
    Terminal=false
    Type=Application
    Categories=AudioVideo;Player;Video;
    Comment=
    Note that Categories should be set appropriately for the application type (in this example, a multimedia app).
    Now update the applications and mime database with:
    Code:
    $ update-desktop-database ~/.local/share/applications
    $ update-mime-database    ~/.local/share/mime
    Programs that use mime types, such as file managers, should now open *.foo files with foobar. (You may need to restart your file manager to see the change.)

    User error. Please replace user and try again

Similar Threads

  1. [SOLVED]
    No KDE file associations
    By SomeDamFool in forum Using Fedora
    Replies: 3
    Last Post: 15th February 2015, 12:22 AM
  2. File associations
    By prkos in forum Using Fedora
    Replies: 4
    Last Post: 6th August 2008, 02:31 AM
  3. File Associations
    By brisray in forum Using Fedora
    Replies: 2
    Last Post: 30th May 2005, 05:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •