Usually you should not do this. As a rule, if your application behaves differently depending on the desktop environment, this will be an unpleasant surprise for any user who switches between them.
Alternative
Use DE-agnostic commands such as xdg-open . Benefits:
- You do not need to write logic yourself (xdg-utils already did this)
- More comfortable. It matches the actual preferences of the user; many users use one DE, but prefer some applications from another DE.
- Supports other DEs such as XFCE, LXDE, Unity, etc.
For example, instead of opening the URL in Firefox or Konqueror according to the current DE, pass the xdg-open URL to open it in your preferred application. (The user may be a Chromium user.) Do not use hard-code nautilus or dolphin for GNOME and KDE; open the path using xdg-open instead.
Similarly, for other forms of interacting with DE, try to use the Freedesktop specifications , rather than trying to guess what DE is. There are standards for moving files to the trash , adding taskbar applets, and adding files to the list of recent files. Among others.
Mechanical snail
source share