[Tutor] Checking the desktop environment

Alan Gauld alan.gauld at btinternet.com
Fri Jun 20 19:34:49 CEST 2008


"Timo" <timovwb at gmail.com> wrote

> Hello all, in my program I need to know what desktop environment the
> user is running.

A few years ago I would have said that meant you had a broken
design since it was very bad practice for any program to depend
on the users environment. nfortunately recent developments in
Linux/X mean that the whole concept is broken that one more
environmentally wawre program probably is no big deal!

But there are caveats that mean you will probably never get
it right in every case. The best you cvan probably do is detect
if the environment is one of a fixed set  known to work with
your code.#

But bear in mind that the user can switch envirojnemts while
your code is running, or may even be runningmultiple
environments simultaneously on virtual windows etc.

Thats why the users environment should be left as as
something for the user and the programming environment
for the programmer.

> I figured this piece of code works, but apparently not
> on every Linux distro. On Ubuntu it did the trick, but then I heard 
> of
> someone who runs SLiM that he get's an error with this.
>
> if os.environ['DESKTOP_SESSION'].startswith('kde'):
>    print "Running KDE"

That would only find out if KDE was beiong used and only
if the user (or cofig scripts) has not modified the variable.

> So, does anyone know a water-proof solution for desktop environment
> checking?

I don't think such a thing can exist on a Unix/X system. An
approximation will be the best you can get.

Can you explain why you need to know?
In most situations there should be a generic way to do it.


Alan G. 




More information about the Tutor mailing list