3

Assume a Linux Desktop Environment system is installed. When powered on and credentials entered, whatever Desktop Environment is started i would consider the default Desktop Environment. The user may pick another Desktop Environment such as KDE or XFCE, but that would not be the default. What is a distribution agnostic snippet of code to find the default Desktop Environment or better yet, the DE last used. The code must run from a remote SSH session or CTRL-ALT-F2 text only console.

The impetus for this question is that i recently emailed the output of nvidia-bug-report.sh to NVIDIA. NVIDIA tech support replied back days later asking "What OS?", "GNOME or KDE?", "What Distribution?" - all meta data that could be automatically collected and catalogued by their own script.

Since the Desktop Environment has crashed, nvidia-bug-report.sh needs to run from a CTRL-ALT-F2 text console or remote SSH session. Clearly, neither of these have the $DESKTOP_SESSION variable. Answer would return one or more items in order of confidence from a list similar to "gnome|kde|mate|cinnamon|lx|xfce|jwm|none".

Choosing between GNOME or KDE in Ubuntu.
Choosing Desktop Environment Session Type in Fedora. Choosing between GNOME or KDE in CentOS.

Would like scripts similar to " How can I get distribution name and version number in a simple shell script? "

9
  • How do you define “default desktop environment”? Do you mean the default for a newly created user account, or for the user account that's running your code? What if the user is running different desktop environments on different consoles? What if the last desktop environment used is not the user's default? Why do you care anyway? Commented Oct 25, 2013 at 23:54
  • Basically, what Gilles said, but please for the love of all that is good consider those of us that do not use a desktop environment (and have absolutely no interest in doing so). i.imgur.com/NHJWjVM.png
    – Chris Down
    Commented Oct 26, 2013 at 5:28
  • @Gilles, the defaults for a newly created user account are along the lines of /bin/bash or /bin/tcsh. Those are shells i am in all day, but they are not at all Desktop Environments. Assume only one DE is running on the machine. Best effort as to what was the last used DE. The code that was running has probably been crashed because the entire GUI has crashed. Have to determine the crashed DE remotely from a non GUI session.
    – rjt
    Commented Oct 26, 2013 at 6:12
  • 3
    You've missed the point. Detecting which desktop environment I use has no point, because I don't use one. Your expectations are fallacious.
    – Chris Down
    Commented Oct 26, 2013 at 6:13
  • Of course i understand some machines have no GUI at all because that is how many of my server systems were setup, so we add none to the list. With the exception of CloudCracker type systems, most servers would never have a dedicated graphics card. But if there is one or more Desktop Environments installed, what is a distro agnostic method to enumerate them?
    – rjt
    Commented Oct 26, 2013 at 6:25

1 Answer 1

1

Maybe this snippet can help if there's no reliable solution offered :

$ w | awk -vdp=$DISPLAY '($2 ~ dp){gsub(/.*\//, "");print $NF}'

or maybe :

$ qdbus | grep -oPm1 '(kdm|xfce|gnome)'

Another approach using pstree :

$ pstree -H $(pidof X) | grep -oP '(kdm|xfce|gnome)(?=.*?X)'
kdm

And one more :

$ lsof ~/.xsession-errors | grep -oEm1 '(kde|xfce|gnome)'
kde

or a variant :

$ lsof ~/.xsession-errors | awk 'NR==2{print $1;quit}'
startkde
6
  • What OS and DE did this work on?
    – rjt
    Commented Oct 25, 2013 at 18:48
  • If the Desktop Environment and XServer have crashed, this may not show.
    – rjt
    Commented Oct 25, 2013 at 18:50
  • # qdbus Could not connect to D-Bus server: org.freedesktop.DBus.Error.Spawn.ExecFailed: /bin/dbus- launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
    – rjt
    Commented Oct 25, 2013 at 22:15
  • @sputnik Assume that gnome or KDE has crashed or is not running or it is being run from a non GUI such as ssh.
    – rjt
    Commented Oct 25, 2013 at 22:22
  • @sputnik, if other methods fail, your scripts would be useful.
    – rjt
    Commented Oct 26, 2013 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .