Chapter 2. Launching the application

Table of Contents

KDE
Gnome
Mac OS X
Windows

With the knowledge of where the file type assocication settings are stored, you could write the code that chooses the right program and launches it.

Fortunately, all systems have either libraries whose methods you can use, and command line programs that do that for you. Using the command line tools is the most convenient method if you don't program for a specific desktop environment or operating system, but have a cross-plattform application written in Java, PHP, Python or Ruby.

Note that you should always use quotes around the filename, as files with spaces in the path will not be launched otherwise.

For running apps in Linux desktop environments, have a look at the Portland project.

KDE

KDE provides the program "kfmclient" tool for working with files. It allows you not only to launch the default app for a given file, but also specify that a specific app should be launched for the file and e.g. launch the file association dialog.

To launch the associated application and cause it to load the file, run the following command:

kfmclient exec filename

The application is automatically launched detached in the background, so that the command immediately returns.

You can detect a running KDE environment by checking the KDE_FULL_SESSION environment variable. It is set to "true" (string) if KDE is running.