On my Lubuntu (18.10), xdg-open launches VLC Player when the file is not associated to any applications.

$ xdg-mime query filetype jquery.js
$ xdg-mime query default application/javascript # no output
$ xdg-open jquery.js
Error: no "view" mailcap rules found for type "application/javascript"
Opening "/tmp/jquery.js" with VLC media player  (application/javascript)

On some files, it launches Calibre's E-book viewer (.rb for example).

EDIT I digged into xdg-open and found it executes following commands:

  1. Check filetype with xdg-mime query filename "$file" and xdg-mime query default $filetype
  2. run-mailcap --action=view "$file"
  3. mimeopen -L -n "$file"

The problem lies in mimeopen.

Then how can I change mimeopen to open any unknown files with featherpad, or specific app? In other words, I'd like to set default fallback application if mimeopen can not find any suitable apps.

  • 1) It looks like it's not a problem of MIME-type/application association. As you say, MIME types are recognized and a default application for them is not set. 2) Looking at /usr/bin/xdg-open: it looks like it's unable to detect your desktop environment. Knowing the output of echo $XDG_CURRENT_DESKTOP and echo $DESKTOP_SESSION might help. 2.1) It looks like it's running run-mailcap and then mimeopen, (in a way that won't show you an application chooser), instead of running the file manager (pcmanfm, right?). – fra-san Nov 10 '18 at 12:34
  • Thanks! I digged into /usr/bin/xdg-open and confirmed that it executes mimeopen -L -n "$file". Now I'm checking mimeopen to find reasons why VLC is associated to these files. – rad164 Nov 15 '18 at 4:14
  • If your xdg-open is not executing open_lxde() you may want to try setting the environment variable XDG_CURRENT_DESKTOP=LXDE. This way xdg-open should try to call pcmanfm instead of mimeopen and, if you are lucky (I'm not on LXDE, cannot test reliably), the file manager could ask you how to open files that have no explicit application association set. – fra-san Nov 15 '18 at 9:22
  • I'm using Lubuntu 18.10 and its DE is now LxQT. And in xdg-open, open_lxqt is just an alias of open_generic. I'll update my question based on our comments. – rad164 Nov 15 '18 at 12:29

From man xdg-mime there is an option: xdg-mime default application mimetype(s) to set default applications. You can use

xdg-mime default featherpad.desktop application/javascript

to make featherpad.desktop as default editor for opening files like application/javascript.

Alternatively you can find a file under /usr/share/applications/ directory like default.list depends upon file manager in my case it is gnome-mimeapps.list (I am having gnome DE and nautilus FM). You can edit this file to launch default applications.

  • I'm afraid but I'd like to change behavior about all unknown files, not only about javascript... – rad164 Nov 6 '18 at 11:01
  • @rad164 see updated answer. – Prvt_Yadav Nov 6 '18 at 11:16

mimeopen treats unknown files as text/plain or application/octet-stream.

To set default application, run mimeopen with -d option. Since I could not find option to specify mimetype, you need to create dummy files at first.

touch text.txt # for text/plain
mimeopen -d text.txt # and choose your favorite app

echo -e \\0 > data.dat # for application/octet-stream
mimeopen -d -M data.dat

or edit "~/.config/mimeapps.list".

[Default Applications]

mimeopen, which is shiped with File-MimeInfo, tries to find applications with parent mimytypes. For example, if the filetype starts with "text/", it has "text/plain" as parent. And all filetype inherits "application/octet-stream".

On mimeopen in my environment, the most "suitable" app for octet-stream is VLC Player and for text/plain, it is Calibre's E-book Viewer. That's why some files are opened with these apps.

  • It seems to detect empty files as text/plain. Wouldn't it be better to set the default for application/octet-stream if that is the root of all mimetypes? At least I was able to get a file detected like that using echo -e \\0 > filename.txt – Jonas Berlin Aug 16 at 5:28
  • 1
    @JonasBerlin I added it to my answer, thanks! – rad164 Aug 16 at 8:48

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.