2

I'm working on a Firefox NPAPI plugin + XPCOM component. I've run into a dilemma: Given a file downloaded from the Internet (say a PDF or PNG) how do I start the default helper application to display that file on Linux using C/C++?

Currently I'm using the system function call to invoke the gnome-open command and passing it the file path. This works on GNOME Desktops, however it won't work across Linux platforms with different desktop environments (including KDE).

So my question is: Is there a standard uniform method to go about this? Are there any recommendations? Any help would be greatly appreciated!

themoondothshine
  • 2,983
  • 5
  • 24
  • 34

2 Answers2

5

The xdg-open command is the standard way to open a file or URL in the user's preferred application.

It should work correctly in different desktop environments.

caf
  • 233,326
  • 40
  • 323
  • 462
1

There is no standard tool to open a file using default application in Linux. It depends on a desktop environment. For Gnome, there is a "gnome-open" tool as you figured out. KDE has its "kde-open" for the same purpose. I would check for gnome-open first and if it doesn't exist, check for kde-open. Otherwise report an error to the user.

Another option is to use Firefox itself to open a file using "file://" protocol. Firefox is able to display PDF files if appropriate plugin is installed, display text files etcetera.

  • There is a standard tool as has already been explained. See [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/). And it does not depend on the desktop environment, since there are numerous specifications that deal with this kind of thing desktop-agnostic, see [mime app spec](https://www.freedesktop.org/wiki/Specifications/mime-apps-spec/). Ofc, every desktop environment likes to do its own thing, which is why xdg-open also calls gnome-open/kde-open if they exist. – hasufell Apr 10 '16 at 03:29