How to properly and easily configure `xdg-open` without any environment?

I’m using OpenBox window manager without any desktop environment.

xdg-open behaves strangely. It opens everything with firefox.

$ xdg-settings --list
Known properties:
  default-web-browser           Default web browser

I’m looking for a simple program; something like reading every *.desktop file in /usr/share/applications/ folder and automatically setting xdg settings.

Asked By: kravemir


On Debian you could use the command, as root

update-mime-database /usr/share/mime

having the shared-mime-info package installed.

Answered By: enzotib

You can install and use perl-file-mimeinfo in the extra repository to manage mimetypes.

Example to open all .pdf files in apvlv:

/usr/bin/vendor_perl/mimeopen -d $file.pdf

or on other Linux distributions where mimeopen is NOT in /usr/bin/vendor_perl/ but is in one of the $PATH directories :

mimeopen -d $file.pdf

and then, at the prompt, enter the application: apvlv.

Answered By: jasonwryan

Why not to use utilities from xdg itself?

To make Thunar the default file-browser, i.e. the default application for opening folders.

$ xdg-mime default Thunar.desktop inode/directory

to use xpdf as the default PDF viewer:

$ xdg-mime default xpdf.desktop application/pdf

This should create an entry

[Default Applications]

in your local MIME database ~/.config/mimeapps.list.

Your PDF files should be opened with xpdf now.

Answered By: lzap

You could use something like this to generate the appropriate xdg-mime commands for each of your .desktop files and the mimetypes they contain, then execute the ones you like. Note /usr/share/applications might have subdirectories.

find /usr/share/applications ~/.local/share/applications -iname '*.desktop' -print0 | while IFS= read -r -d $'' d; do
  for m in $(grep MimeType "$d" | cut -d= -f2 | tr ";" " "); do
    echo xdg-mime default "'$d'" "'$m'"
Answered By: aleb

Adding to what everyone said, Make sure you have no overlapping applications being used.

For example let us assume you want to change the default magnet link to use qbittorrent so you type

xdg-mime default org.qbittorrent.qBittorrent.desktop x-scheme-handler/magnet

But when you type this and check your current default magnet

xdg-mime query default x-scheme-handler/magnet

It shows some other application for example popcorntime.desktop which isn’t what you want.

So to fix this:

Using a File manager, go to /usr/share/applications and find popcorntime.desktop

Right click it and then click properties.

Go to the Applications tab.

In the Supported file types: area, remove the Mimetype application/x-bittorrent

Then go ahead and click ok

Notice how when you open properties again and check, you find that nothing has changed and it went back to how it was.

But it actually got deleted for a second and got reconfigured, which is why now the command

xdg-mime default org.qbittorrent.qBittorrent.desktop x-scheme-handler/magnet

which was already set in mimeapps.list will get applied.

Answered By: Kazem Sami

For those like me that did not know how to get the proper mimetype to use with xdg-mime:

1- Initial situation:

$ xdg-open . opens vscodium (who hardcoded this stupid file association?) :[

2- Problem: what is the mime type of "."?

$ mimetype .
.: inode/directory

3- Solution:

$ xdg-mime default thunar.desktop inode/directory

NOTE: Following line doesnot work but no error is reported :{
$ xdg-mime default Thunar.desktop inode/directory

Answered By: liar666