Search code examples
pythonlinuxenvironment

What is my current desktop environment?


How can I get to know what my desktop environment is using Python? I like the result to be gnome or KDE or else.


Solution

  • Tested in Ubuntu 9.10:

    >>> import os
    >>> os.environ.get('DESKTOP_SESSION')
    'gnome'
    

    Edit 2: As comments say, this is beginning to be even less reliable with newer GNOME versions. I'm now also running Ubuntu 18.04, and it returns 'ubuntu' instead of the prior 'gnome'.

    Edit 1: As mentioned in comments below, this approach will not work for more some OSes. The other two answers provide workarounds.