def IsTextConsole():
  try:
    # see TN2083
    security_lib = ctypes.cdll.LoadLibrary(
        '/System/Library/Frameworks/Security.framework/Security')

    # Security.Framework/Headers/AuthSession.h
    session = -1
    session_id = ctypes.c_int(0)
    attributes = ctypes.c_int(0)

    ret = security_lib.SessionGetInfo(
        session, ctypes.byref(session_id), ctypes.byref(attributes))

    if ret != 0:
      return True

    return not attributes.value & SESSIONHASGRAPHICACCESS
  except OSError:
    return True
Checks if console is test only or GUI.
dataset/ETHPy150Open google/macops/gmacpyutil/gmacpyutil/gmacpyutil.py/IsTextConsole