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? "

rjt
  • 377
  • 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? – Gilles 'SO- stop being evil' Oct 25 '13 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). http://i.imgur.com/NHJWjVM.png – Chris Down Oct 26 '13 at 05: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 Oct 26 '13 at 06: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 Oct 26 '13 at 06: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 Oct 26 '13 at 06:25
  • @sputnick, please put your first answer back, the one with something like: w | awk | egrep -i "gnome|kde|mate|cinnamon|lx|xfce|jwm|none" . It would work from a text console as long as the DE is still running. – rjt Oct 26 '13 at 17:09
  • Running a GUI doesn't imply a desktop environment. It could be a window manager (or theoretically there might not even be a window manager, although in practice nobody does that). You cannot determine which window manager was run last except through crude heuristics (figure out which user last used X then try to see what window manager he ran at that time or try to dig through his configuration file). But I don't see how that information could be relevant. It's irrelevant to analyze GUI crashes, for example — the applications that were running might matter but hardly ever the WM. – Gilles 'SO- stop being evil' Oct 28 '13 at 23:28
  • i do not know about the window manager, but personal experience has shown subtle bugs when an app runs fine in Gnome, but not in KDE. NVIDIA device driver developers think the Desktop Environment and applications and OS matter when it comes to reporting their bugs. i am trying to make bug reporting to nvidia easier for myself as my system has gone from rock solid to i never know when it will crash. – rjt Oct 29 '13 at 00:08
  • the main thing I got from this post ended up being that I miss GDM 2 (and apparently still have not gotten over my GNOME 2 withdrawal phase) – strugee Oct 29 '13 at 03:56

1 Answers1

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