6

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?

7

In my knowledge you can set a default app through xdg-mime.

xdg-mime default okular.desktop application/pdf

To check if it worked:

xdg-mime query default application/pdf
  • 1
    After running this, PDF documents are still being opened by Evince. Anything else I should do? – Luís de Sousa Aug 1 '16 at 9:47
1

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).

#!/bin/bash

if [ -e ~/.local/share/applications/defaults.list ]
then
    echo "The file exists"
    sed 's/evince/okular/' ~/.local/share/applications/defaults.list > ~/.local/share/applications/defaults.list
else
    echo "The file does not exist"
    sed 's/evince/okular/' /usr/share/applications/defaults.list > ~/.local/share/applications/defaults.list
fi
  • This works for me. ~/.local/share/applications/defaults.list was exist but empty other than the header on the first line. What I did was to copy the line from /usr/share/applications/defaults.list which define application/pdf and make change so okular.desktop is the first option. – aasril Aug 26 '18 at 7:49
0

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!

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.