10

I run Debian Jessie without a desktop environment (I use the tiling window manager i3) and like to use xdg-open to quickly open files using a preferred application. I have an ongoing problem setting the preferred app for PDF files though. This is my problem in a nutshell:

$ xdg-mime query filetype ~/Downloads/document.pdf
application/pdf

$ xdg-mime query default application/pdf
/usr/share/applications/qpdfview.desktop

$ xdg-open ~/Downloads/document.pdf
[opens gimp!]

Any ideas would be hugely appreciated - this has been plaguing me for about a year. The only way I've ever managed to (temporarily) fix it is by directly editing the mimeinfo.cache and removing the reference to gimp from the application/pdf record.

And yes, /usr/share/applications/qpdfview.desktop exists and contains the correct location of the qpdfview binary. (Indeed, this .desktop file is used when I hand-edit mimeinfo.cache.)

slm
  • 363,520
  • 117
  • 767
  • 871
Tim
  • 203
  • 2
  • 5

1 Answers1

10

You could attempt to manually set it via the command line using mimeopen.

Example

$ mimeopen -d ~/test.pdf

Please choose a default application for files of type application/pdf

    1) E-book Viewer  (calibre-ebook-viewer)
    2) Document Viewer  (evince)
    3) Xournal  (xournal)
    4) GNU Image Manipulation Program  (gimp)
    5) Xpdf PDF Viewer  (xpdf)
    6) Print Preview  (evince-previewer)
    7) Inkscape  (inkscape)
    8) calibre  (calibre-gui)
    9) Other...

use application #2
Opening "/home/saml/Downloads/test.pdf" with Document Viewer  (application/pdf)

Which results in my PDF file, test.pdf opening up in Evince. From this point on Evince is the default when I use xdg-open.

References

slm
  • 363,520
  • 117
  • 767
  • 871
  • 2
    Thanks! I still don't know why the problem existed in the first place, but at least the default now seems to persist beyond an apt-get dist-upgrade. – Tim Jun 05 '14 at 02:30
  • @Tim - glad this resolved your issue. – slm Jun 05 '14 at 02:34
  • 3
    Why does this work, but setting the default application using `xdg-mime` doesn't work? This is the kind of stuff that drives me insane! To elaborate, I tried `xdg-mime default /usr/share/applications/evince.desktop application/pdf`, and `xdg-mime query filetype /some/file.pdf` confirmed that the default application was set, but `xdg-open` completely ignored my preferences and opened Print Preview instead. – Hubro Jan 25 '16 at 12:29
  • 3
    @Hubro `xdg-open` is a shell script wrapper for opener commands of various desktop environment. I guess you could try running `sh -x $(which xdg-open) /some/file.pdf`, figuring out which actual opener command is called, then hope to find out where to searching for next... – Naitree Jun 10 '17 at 03:01
  • @sim Sorry but why was this the accepted answer? The answer seems to provide a workaround (it does not in my case) but does not actually answer the issue of why xdg-open ignores the xdg-mime query. – TSGM Dec 29 '20 at 23:08
  • @sim I can confirm that the tip of using the sh -x command helped in my case as it allowed me to track down that the opener command was shuffling things to gnome-default-applications-properties, after which I could correct the default application via the gnome file browser. – TSGM Dec 29 '20 at 23:12