Default applications (mime) for everything?

Hello,

So, recently I realized that the default application for opening anything was visual studio code. For example, when I selected “open dropbox folder” in the dropbox tray icon, VSCode would start up showing that folder. When I clicked on a file path in terminal windows the VSCode editor would open that file.

I uninstalled VSCode and everything switched to using “Lapce” (another editor installed in my system).

I went to “Settings → Default Applications” to see if I can change things there, but there’s only a handful of applications. Interestingly I noticed that “Calendar” (I do not have a calendar app) was set to “Lapce”.

So there must be something I did to mess up my “open with” settings. I found that xdg-utils can be used to query and set mime types, but I would like to reset to all defaults as I do not know what I did to cause this and how I messed it up.

How do I “erase” any “open with” configuration so that everything reverts to defaults?

Disclaimer: At your own risk, after RTFM XDG_MIME_Applications → mimeapps.list

Delete from your local user account any *mimeapps.list file and relogin.

rm -iv ~/.config/*mimeapps.list

Thank you for the assistance. I read the instructions and after taking a backup of the file and deleting it, I still get the same behavior.

Weirdly enough, I have none of the files in the linked documentation:

[user@host xdg]$ ls ~/.config/mimeapps.list  /etc/xdg/mimeapps.list ~/.local/share/applications/mimeapps.list /usr/local/share/applications/mimeapps.list /usr/share/applications/mimeapps.list
ls: cannot access '/home/user/.config/mimeapps.list': No such file or directory
ls: cannot access '/etc/xdg/mimeapps.list': No such file or directory
ls: cannot access '/home/user/.local/share/applications/mimeapps.list': No such file or directory
ls: cannot access '/usr/local/share/applications/mimeapps.list': No such file or directory
ls: cannot access '/usr/share/applications/mimeapps.list': No such file or directory

Yet still, when I query what opens a folder I get:

[user@host xdg]$ xdg-mime query default inode/directory
dev.lapce.lapce.desktop

This is the same as the behaviour in Gnomes “Settings → Default applicaitons” where after uninstalling VSCode it switched “Calendar” to Lapce as the default (instead of VSCode).

I removed lapce and this happened:

[user@host ~]$ yay -Rncs lapce
[sudo] password for user:
checking dependencies...

Package (1)  Old Version  Net Change

lapce        0.2.7-1      -93.16 MiB

Total Removed Size:  93.16 MiB

:: Do you want to remove these packages? [Y/n]
:: Processing package changes...
(1/1) removing lapce                                                                             [--------------------------------------------------------] 100%
:: Running post-transaction hooks...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Updating the desktop file MIME type cache...

[user@host ~]$ xdg-mime query default inode/directory
org.gnome.Nautilus.desktop

This is finally sensible. But still, the “Settings → Default applicaitons” now gives “Neovim” which tells me I still have a problem… In fact, I re-installed lapce and got back to the editor being used:

[user@host ~]$ xdg-mime query default inode/directory
dev.lapce.lapce.desktop

So it seems to me that that somehow GNOME decides to use the “editor” for missing mime types? Where would I find this configuration so I can fix it?

EDIT: I reinstalled visual-studio-code-bin and now:

[user@host ~]$ xdg-mime query default inode/directory
code.desktop

I found how to enable debugging output:

[user@host ~]$ XDG_UTILS_DEBUG_LEVEL=2 xdg-mime query default inode/directory
Checking /home/user/.local/share/applications/defaults.list and /home/user/.local/share/applications/mimeinfo.cache
Checking /home/user/.local/share/applications/defaults.list and /home/user/.local/share/applications/mimeinfo.cache
Checking /home/user/.local/share/flatpak/exports/share/applications/defaults.list and /home/user/.local/share/flatpak/exports/share/applications/mimeinfo.cache
Checking /home/user/.local/share/flatpak/exports/share/applications/defaults.list and /home/user/.local/share/flatpak/exports/share/applications/mimeinfo.cache
Checking /var/lib/flatpak/exports/share/applications/defaults.list and /var/lib/flatpak/exports/share/applications/mimeinfo.cache
Checking /var/lib/flatpak/exports/share/applications/defaults.list and /var/lib/flatpak/exports/share/applications/mimeinfo.cache
Checking /usr/local/share/applications/defaults.list and /usr/local/share/applications/mimeinfo.cache
Checking /usr/local/share/applications/defaults.list and /usr/local/share/applications/mimeinfo.cache
Checking /usr/share/applications/defaults.list and /usr/share/applications/mimeinfo.cache
code.desktop

None of the defaults.list list files above exist on my system! Yet some of the cache files exist and I think I located the problem here:

[user@host ~]$ grep lapce /usr/share/applications/mimeinfo.cache
inode/directory=code.desktop;dev.lapce.lapce.desktop;org.gnome.Nautilus.desktop;
text/plain=code.desktop;dev.lapce.lapce.desktop;nvim.desktop;

What creates /usr/share/applications/mimeinfo.cache and how can I re-create it?

I’ve faced this issue a few months ago and try almost every answer to this question, but the solution is the less voted one: use xdg-mime to restore default application:

xdg-mime default org.gnome.Nautilus.desktop inode/directory

Just replace the name if you’re not using nautilus as your file manager.

1 Like

It seems to me that the problem is from the packagers for these applications. They hijack associations that should not be there:

$ grep "inode/directory" *.desktop
code.desktop:MimeType=text/plain;inode/directory;application/x-code-workspace;
dev.lapce.lapce.desktop:MimeType=text/plain;inode/directory;
org.gnome.Nautilus.desktop:...

Why on earth do the packagers for lpace/vscode specify these associations? If they come from upstream the maintainers should remove them.

I uninstalled both applications and used flatpak install com.visualstudio.code dev.lapce.lapce to get them instead. The flatpak packages seem to leave the inode/directory association out so I’m getting correct behaviour…

EDIT: Futhermore I like this workaround where you copy the .desktop file to your home ~/.local/share/applications folder and edit them to remove the association.

1 Like

In order to have a better understanding on the issue, read the full article, and also about Default applications.

In short :

  • The system maintains system and user databases with mime info, called cache (extension .cache).
  • Database re-construction follows rules/directives from packages/applications, so each app vendor/developer/packager designs specific rules about the functionalities that their package/program can provide.
  • Files existing locally override same directives from system files.
  • Local cache can be deleted, or rebuilt, only by the user.
  • System cache is re-built after package activities (install/update/remove), automatically
  • Relevant packages are shared-mime-info and desktop-file-utils, with theses respective commands: update-mime-database update-desktop-database, which have man pages for instructions/explanations.
  • Gnome and other DEs add their own flavor to this whole mess, to avoid it being a boring issue… :rofl:

Give feedback after reading and testing. :wink:

Hello @petsam,

I’ve understood how this works but what I’m missing and can’t find is how the system selects the proper application when multiple advertise the same capability.

For example, I was interested in what opens a directory (which I expect to be the file manager). Knowing what I know now, directories have this mime type:

$ xdg-mime query filetype .
inode/directory

The lapce and visual studio code packages have .desktop files that both advertise this capability (same as like nautilus does for gnome). For example (same is for vs code):

$ yay -Ql lapce | grep desktop
lapce /usr/share/applications/dev.lapce.lapce.desktop

$ grep -i mimetype /usr/share/applications/dev.lapce.lapce.desktop
MimeType=text/plain;inode/directory;

This is not wrong. Running either with a directory (e.g. lapce . or code .) as the item to open will open the application focused on that directory. However, it seems to me that the update system that parses the desktop files and generates the mime cache seems to use “alphabetical order” to decide what is used.

I had nautilus which is what I (and I suppose 90% of users) expect will be used when running xdg-open . (i.e. open a directory with associated application should bring up a file manager). However after installing lapce the mime cache was updated so that:

$ xdg-mime query default inode/directory
dev.lapce.lapce.desktop

If I then install VS Code, suddenly:

$ xdg-mime query default inode/directory
code.desktop

Installing them in different order yields the same result. The cache always gets:

$ grep directory /usr/share//applications/mimeinfo.cache
inode/directory=code.desktop;dev.lapce.lapce.desktop;org.gnome.Nautilus.desktop;

It seems to be alphabetical (c, l , o) ordering…

Either way, now that I understand this, I guess I can use what @Triby suggested to override: xdg-mime default org.gnome.Nautilus.desktop inode/directory

More easily, I can right-click on any folder in Nautilus, select “Open With…” and then pick “Files” from the list of applications (which I guess does the same thing behind the scenes)…

I do get it now, just annoyed with how the default behavior seems to work. It’d be better if the “order of installation” is used when generating the cache. This way installing new applications would not “surprise” you like it did for myself. Since nautilus was the first thing I installed and what was opening folders, installing lapce/code afterward should not change this unless I explicitly choose to… (but I guess that’s just my preference).

Exactly. That’s why there are user level settings, so each user applies his own preference. :person_shrugging:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.