def _available_services(refresh=False):
    """
    This is a helper function for getting the available macOS services.

    The strategy is to look through the known system locations for
    launchd plist files, parse them, and use their information for
    populating the list of services. Services can run without a plist
    file present, but normally services which have an automated startup
    will have a plist file, so this is a minor compromise.
    """
    if "available_services" in __context__ and not refresh:
        log.debug("Found context for available services.")
        __context__["using_cached_services"] = True
        return __context__["available_services"]

    launchd_paths = {
        "/Library/LaunchAgents",
        "/Library/LaunchDaemons",
        "/System/Library/LaunchAgents",
        "/System/Library/LaunchDaemons",
    }

    agent_path = "/Users/{}/Library/LaunchAgents"
    launchd_paths.update(
        {
            agent_path.format(user)
            for user in os.listdir("/Users/")
            if os.path.isdir(agent_path.format(user))
        }
    )

    result = {}
    for launch_dir in launchd_paths:
        for root, dirs, files in salt.utils.path.os_walk(launch_dir):
            for file_name in files:
                data = _read_plist_file(root, file_name)
                if data:
                    result[data["plist"]["Label"].lower()] = data

    # put this in __context__ as this is a time consuming function.
    # a fix for this issue. https://github.com/saltstack/salt/issues/48414
    __context__["available_services"] = result
    # this is a fresh gathering of services, set cached to false
    __context__["using_cached_services"] = False

    return result