How can I detect when I'm on a system running Unity?
Asked Answered
E

4

5

In order to choose between what type of app indicators to use for a program, I need to detect whether I'm in a Unity desktop or not. Is this possible? Is it possible when I don't have access to the environment?

Edrick answered 5/1, 2012 at 12:50 Comment(3)
Found this: askubuntu.com/questions/70296/…Otherworldly
I've edited my question, I may not have access to the environment, so that is not a complete solution.Edrick
Another way would be to check if a process named 'unity' is running. I don't think there's a cross-platform way to do this. For Linux, you may want to look at: #940278Otherworldly
D
4

It looks like there's also XDG_CURRENT_DESKTOP:

rubiojr@rubiojr-VirtualBox:~$ echo $XDG_CURRENT_DESKTOP 
Unity

See https://askubuntu.com/questions/70296/is-there-an-environment-variable-that-is-set-for-unity

Despotic answered 23/11, 2012 at 9:46 Comment(1)
Yes, this is in the output of env.Andersonandert
F
3

In Ubuntu you can use following commands:

  • echo $DESKTOP_SESSION: This command return ubuntu when you are using Unity and ubuntu-2d when you are using Unity 2D and ...
  • sudo grep "Starting session" /var/log/lightdm/lightdm.log: Because of last version of Ubuntu use lightdm as display manager you can see last line of the lightdm.log file.
Flowerdeluce answered 2/9, 2012 at 4:27 Comment(0)
A
2

Just shell execute ps aux | grep unity, this is cross-plattform for linux. Even works on ARM cores.

On my 11.04 Ubuntu running unity it returns unity-2d-panel, unity-2d-launcher and more processes. Can't confirm if this is true on every linux platform.

Abnegate answered 5/1, 2012 at 14:17 Comment(1)
There can be other sessions (belonging to the current user or a different user) running Unity when your current session may not be it. I would advise against relying on existence of a Unity process.Clementeclementi
A
1

Look in the list of environment variables for unity by running this command line:

env | grep -i unity

If as in this answer you see XDG_CURRENT_DESKTOP=Unity then you know it is in use. Alternatively, you could of course check for desktop rather than unity.

Andersonandert answered 3/1, 2014 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.