how can i get from python that, what is my desktop environment i mean I like the result be gnome or KDE or else
+4
A:
Tested in Ubuntu 9.10:
>>> import os
>>> os.environ.get('DESKTOP_SESSION')
'gnome'
Edit: As mentioned in comments below, this approach will not work for more some OSes. The other two answers provide workarounds.
Adam Bernier
2010-01-10 01:09:23
and on fedora11! thanks a lot!
ali
2010-01-10 01:10:59
Was just in the middle of writing an answer that involved enumerating processes but this is much better.
mdm
2010-01-10 01:12:37
On Mac OS X 10.6.2 `os.environ.get('DESKTOP_SESSION')` returns `"None"`
Daniel Vassallo
2010-01-10 01:16:44
i think because mac has only one!
ali
2010-01-10 01:20:39
On my openSUSE 11.1 system, DESKTOP_SESSION is set to 'default'.
R Samuel Klatchko
2010-01-10 02:20:59
This returns nothing at all for me. Rather, None.I'm using KDE on Ubuntu, but I'm not using a login manager (that is, no KDM or GDM).
Alex JL
2010-01-10 09:27:41
+2
A:
You might try this:
def detect_desktop_environment():
desktop_environment = 'generic'
if os.environ.get('KDE_FULL_SESSION') == 'true':
desktop_environment = 'kde'
elif os.environ.get('GNOME_DESKTOP_SESSION_ID'):
desktop_environment = 'gnome'
else:
try:
info = getoutput('xprop -root _DT_SAVE_MODE')
if ' = "xfce4"' in info:
desktop_environment = 'xfce'
except (OSError, RuntimeError):
pass
return desktop_environment
And read the discussion here: http://ubuntuforums.org/showthread.php?t=1139057
Mef
2010-01-10 01:11:24
That works for my desktop to detect KDE (unlike DESKTOP_SESSION, which returns None)
Alex JL
2010-01-10 09:28:43
+3
A:
Sometimes people run a mix of desktop environments. Make your app desktop-agnostic using xdg-utils; that means using xdg-open
to open a file or url, using xdg-user-dir DOCUMENTS
to find the docs folder, xdg-email
to send e-mail, and so on.
Tobu
2010-01-10 01:22:04