1

Is it possible to check if a UNIX machine (Mac / Linux) has a GUI?

Basically I would like to distinguish between:

  • UNIXes with GUI (i.e. normal Macs, Linuxs)
  • UNIXes with no GUI (i.e. Mac server/ linux server etc.)

I have tried to use the $DISPLAY variable, but I don't think it works in Mac OS (It doesn't on my Yosemite installation).


Background

I am writing a (ruby) script that starts up a local server on the UNIX machine and then opens this local server in the default browser (using open http://localhost:4567 or xdg-open http://localhost:4567 depending on the OS).

The problem is that this script is likely to be used on servers as well as on normal computers (i.e. machines with and without a GUI) and I don't want to annoy users on servers by opening the local server URL in a command line browser (such as lynx etc.).

NB. I plan to check the $SSH_CLIENT variable (etc.) before I test for the GUI. Thus, the script will not try to open the default browser if you SSH into a machine. So the above is to target users that physically connect to a server (and not through SSH).

  • The $DISPLAY variable does not work on macs because they no longer use X11 : see here – Ismail Moghul Mar 6 '15 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.