Fix Firefox's 'Show in Folder' not opening in File Manager
Tags: linux, webdev, computerscience, tutorial
Published: 2022-06-07 14:21:05

## Introduction

Hey fellow Devs, it's Ritika here.

I recently installed Gnome Shell as my Window Manager on my Linux environment, and some of my default settings got changed as a result. One of them is Firefox not opening the downloaded file location in File Manager, instead trying to open it in FreeCAD, a parametric 3D modeler software.

## The problem
![The problem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/srauzskmej2bpnchoc8i.gif)
Unfortunately, this is not something you can configure in the General settings in Firefox.

![Firefox Preferences](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5zoy2qrguelse462tja.png)

## Why it happens (MIME types)

There's more to opening a file than just knowing its extension and the default application you've set it to open with.

A MIME type (Multipurpose Internet Mail Extensions type) indicates the nature and format of a document, file, or assortment of bytes. (Source: [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types))

In Linux, these MIME types are commonly defined in a file `mimeinfo.cache`.
A MIME type has two parts: a type and a subtype, separated by a slash (/). It is accompanied by a value on the right side of the equals (=) sign.
```
type/subtype=value

Examples:
text/plain=featherpad.desktop;libreoffice-writer.desktop;
video/mp4=vlc.desktop;
```
As you can see, there can be multiple values after the equals (=) sign, which are separated by semicolons (;).

The values are written in an order of priority: since `featherpad.desktop` is before `libreoffice-writer.desktop`, FeatherPad receives more importance and hence if it is installed, files of MIME type "`text/plain`" will always be opened with FeatherPad.
If someone were to uninstall FeatherPad from their system, `Libreoffice Writer` will now be given preference to open files of the same MIME type.

![Examples of MIME types from mimeinfo.cache file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uo1y4f3aapa0wprj0kvm.gif)

## Our issue

In our case, we are unable to open Folder location in File Manager, instead it opens in an app called FreeCAD.
Directories have the MIME type of `inode/directory`, so we'll look for this in our `mimeinfo.cache` file.

## The solution

Open up your terminal, and execute the following commands:
```
cd /usr/share/applications
sudo nvim mimeinfo.cache
```
If you do not have `nvim` installed, you can also use `gedit` or `vi` to open the file with:
```
sudo gedit mimeinfo.cache
```

![Finding inode/directory value in mimeinfo.cache](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g65v4jurecblyjh143el.png)
 
Sure enough, the first value for `inode/directory` is `FreeCAD.desktop`. We need to remove it, so that `pcmanfm-qt.desktop` can have the most priority for our folder opening actions.

Save and close the file using `:wq` if you're using nvim or vim.

## Why sudo?
If we don't access the file with root permissions, the file stays **read-only** for us, hence even if we open the file and make changes, we won't be able to save our changes.
`sudo` enables us to make changes to `mimeinfo.cache` and save it.

## Finally
After you save the file, the change should take effect even without logging out or restarting your PC. Still it's good to restart and see if our changes stick.

![Solved](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5d67jtlrphvue5glmrr1.gif)

In case you've edited the `mimeinfo.cache` file and changes still don't take place, remove the MimeType of `inode/directory` after opening the Application's desktop file from the same directory, for example 
```
sudo nvim FreeCAD.desktop
```
and saving the changes.

![Editing MimeType in application's desktop file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91f5lvr5s6uqse86g230.png)

Did you find this useful? Comment below if you did, or if you faced any difficulty, let me know below. Wishing you a productive day ahead!