I need to know if my program running on OSX is in a graphic capable environment ?

are we running via ssh through a console only pipe ?

on most unix I would test for DISPLAY in the environment variables, but how do you test this on OSX ?


1 Answer 1


It is my understanding that the loginwindow process isn't running if OS X is not launched in GUI mode (like when you boot in single user mode or if this is a server you're connecting to via SSH).

So I suppose that if a grep on loginwindow returns empty, you know the machine is not in GUI mode, for example:

ps auxww | grep "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" | grep the_logged_in_username | grep -v "grep" | awk '{print $2}'

would return the PID of loginwindow if the process is launched or return nothing if the process is not launched.

Note that I have not tested, it's just an idea, I don't know for sure if it works...

  • Wouldn't this provide a positive result if some GUI session is running for the specified user? Also, I have my doubts that this is guaranteed by spec somewhere, but who knows...
    – user
    Nov 18, 2016 at 13:40
  • No idea - I didn't run any tests, I just thought sharing this idea could be helpful... but really I'm not sure.
    – Eric Aya
    Nov 18, 2016 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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