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 ?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI 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 ?
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...