Results 1 to 2 of 2

Thread: linux set file associations from the command line

  1. #1
    Join Date
    Aug 2008
    Beans
    573

    linux set file associations from the command line

    At various times it is helpful to know how to setup file associations from the command line. Sometimes file managers just won't work, other times you may have a corrupted file or bad line in your file. I will give 3 examples.

    Pick out out a file of the type of file you want to set.
    I picked an avi, m4a, and jpg.
    Then query the file to figure out the mimetype syntax.
    Code:
    xdg-mime query filetype /home/bob/Downloads/vid1.avi
    Check what the default program is of that mimetype.
    Figure out what the programname.desktop of the program you want to use is. The simplest way to do this is by checking your mimeapps.list file located here. Obviously change your username.
    Code:
    vi /home/bob/.local/share/applications/mimeapps.list
    If that doesn't work try searching for the file with a similar command.
    Code:
    find / -iname '*vlc.desktop*' 2>/dev/null
    If the programname.desktop file has a weird name then you will need to grep for that file. Handbrake has the weirdest file name I have seen so I will use that as my example.
    Code:
    sudo grep -riI "handbrake" /usr/share/applications/* 2>/dev/null
    /usr/share/applications/ghb.desktop:Name=HandBrake
    Check what the default program is of that mimetype.
    Code:
    xdg-mime query default video/x-msvideo
    Set the file association.
    Code:
    xdg-mime default vlc.desktop video/x-msvideo
    The examples.
    Code:
    xdg-mime query filetype /home/bob/Downloads/vid1.avi
    xdg-mime query default video/x-msvideo
    xdg-mime default vlc.desktop video/x-msvideo
    Code:
    xdg-mime query filetype /media/3CACE1E0ACE194A4/Anthem.m4a
    xdg-mime query default audio/mp4
    xdg-mime default vlc.desktop audio/mp4
    Code:
    xdg-mime query filetype /home/bob/Downloads/shellr.jpg
    xdg-mime query default image/jpeg
    xdg-mime default gwenview.desktop image/jpeg
    Verify that what you were trying to set worked. First check the mimeapps.list. Then use your favorite file manager to verify your work or use xdg-open.
    Code:
    vi /home/bob/.local/share/applications/mimeapps.list
    Code:
    xdg-open /home/bob/Downloads/vid1.avi

  2. #2
    Join Date
    Aug 2010
    Beans
    238
    Distro
    Ubuntu Studio 20.04 Focal Fossa

    Re: linux set file associations from the command line

    Doesn't work for me. After "xdg-mime default ... ..." I have this in mimeapps.list:

    Code:
    text/x-lilypond=frescobaldi.desktop
    That's based on:

    Code:
    $ xdg-mime query filetype ~/...../middle-fast-1b.ly
    text/x-lilypond
    I also logged out and logged back in, but xdg-open still insists on opening .ly files in gedit.

    More ideas?

Bookmarks

Posting Permissions

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