Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This question already has an answer here:

I want to see Display Manager name (Gnome, KDE etc.) via python or bash script. Is there any command for it as uname? (I try fedora and Debian)

share|improve this question

marked as duplicate by Michael Mrozek May 23 '13 at 3:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

"GUI" is a bit vague. Are you interested in your desktop environment, your window manager or your display manager? For finding out the session manager on Debian, for example, you can use readlink /etc/alternatives/x-session-manager but this is definitely not portable (doesn't work on Fedora). – Joseph R. May 22 '13 at 14:01
You can try [xwininfo -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')][1] for the current window. [1]: – l0b0 May 22 '13 at 14:03
How do you plan to select the application if you don't know it's name? Is it a GUI that Python or Bash would've started up initially? xwininfo can give you information about the various GUI's running. – slm May 22 '13 at 14:03
I want to install a package according to the type of GUI via script. My script must know the GUI name. Thus I asked the question. – Gyhot May 22 '13 at 14:19
I wrote wrong. My question is relevant with Display Manager or Desktop Manager. – Gyhot May 22 '13 at 14:30

2 Answers 2

up vote 2 down vote accepted

You may probably check the environment variable named DESKTOP_SESSION.

share|improve this answer
This seems to work well enough. Interestingly, though, I tried it in a root terminal (after su) and it was unset. – Joseph R. May 22 '13 at 14:29
It reports default on my system. Not very helpful. – Marco May 22 '13 at 14:30
@JosephR. that is probably because the root user has not started any Desktop Session, it is your user who has launched it. – terdon May 22 '13 at 16:43
You're right. I was substituting my user's environment with root's (via su -) – Joseph R. May 22 '13 at 16:46
@Marco it should contain the desktop name choosen by the user at login time. If the content is default, then I think, it gets the first one in /usr/share/xsessions. – eppesuig May 23 '13 at 8:04

As @eppesuig has said, the environment variable DESKTOP_SESSION may tell you the currently running session.

But that doesn't mean it is the only – or even normal – Desktop environment in use on that system. I usually use GNOME3, but sometimes I boot into KDE or Enlightenment.

If the point of this is to select a desktop-specific GUI package for installation, this really should be used to suggest a default option rather than making a firm decision. If I happened to be running KDE when I installed your app, I would be disappointed to discover I had only installed a QT interface if a GTK interface was available.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.