A long time ago it was possible to set default applications through the command line in the file ~/.local/share/applications/defaults.list
. But this file is no longer around.
How could I set Okular as the default document reader in Ubuntu 16.04 using the command line?
In my knowledge you can set a default app through xdg-mime.
To check if it worked:
Default applications seem to be set globally in the
/usr/share/applications/defaults.list
as association pairs between application and file. User specific file associations can be set in the file~/.local/share/applications/defaults.list
. This file may not exist - perhaps after a fresh Ubuntu install - but can be created by the user.I now use a script like the one below to associate applications to file types. In this example Okular is associated with all document types (replacing Evince).
The following worked for me:
xdg-mime default okularApplication_pdf.desktop application/pdf
I used Alex's previous answer (sorry, I could not comment it...) and updated it.
The line:
xdg-mime query default application/pdf
works well.Now, all my pdfs are opened with Okular by default. Thank you, Alex!