def console_user(username=False):
    """
    Gets the UID or Username of the current console user.

    :return: The uid or username of the console user.

    :param bool username: Whether to return the username of the console
    user instead of the UID. Defaults to False

    :rtype: Interger of the UID, or a string of the username.

    Raises:
        CommandExecutionError: If we fail to get the UID.

    CLI Example:

    .. code-block:: bash

        import salt.utils.mac_service
        salt.utils.mac_service.console_user()
    """
    try:
        # returns the 'st_uid' stat from the /dev/console file.
        uid = os.stat("/dev/console")[4]
    except (OSError, IndexError):
        # we should never get here but raise an error if so
        raise CommandExecutionError("Failed to get a UID for the console user.")

    if username:
        return pwd.getpwuid(uid)[0]

    return uid