//go:build darwin package originclient import ( "context" "os/exec" "regexp" "time" ) var ioregUUIDPattern = regexp.MustCompile(`"IOPlatformUUID" = "([0-9A-Fa-f-]+)"`) // machineID reads the hardware IOPlatformUUID via ioreg, which is stable // across reboots and unique per physical/virtual Mac. func machineID() (string, error) { ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() out, err := exec.CommandContext(ctx, "ioreg", "-rd1", "-c", "IOPlatformExpertDevice").Output() if err != nil { return "", err } match := ioregUUIDPattern.FindSubmatch(out) if match == nil { return "", errMachineIDUnavailable } return string(match[1]), nil }