diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index 3b7c77dc888..3181751005a 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -138,16 +138,22 @@ def _get_service_pids() -> set: timeout=5, ) if result.returncode == 0: - # Output: "PID\tStatus\tLabel" header, then one data line - for line in result.stdout.strip().splitlines(): - parts = line.split() - if len(parts) >= 3 and parts[2] == label: - try: - pid = int(parts[0]) - if pid > 0: - pids.add(pid) - except ValueError: - pass + # Try plist format first (macOS 26+): "PID" = ; + pid = _parse_launchd_pid_from_list_output(result.stdout) + if pid is not None and pid > 0: + pids.add(pid) + else: + # Fall back to legacy tab-separated format: + # "PID\tStatus\tLabel" + for line in result.stdout.strip().splitlines(): + parts = line.split() + if len(parts) >= 3 and parts[2] == label: + try: + pid = int(parts[0]) + if pid > 0: + pids.add(pid) + except ValueError: + pass except (FileNotFoundError, subprocess.TimeoutExpired): pass @@ -1129,7 +1135,37 @@ def _recover_pending_systemd_restart( return False +def _parse_launchd_pid_from_list_output(output: str) -> int | None: + """Extract the PID from ``launchctl list