(title string)
| 2033 | } |
| 2034 | |
| 2035 | func focusCursorWindowByTitle(title string) (bool, string, error) { |
| 2036 | trimmed := strings.TrimSpace(title) |
| 2037 | if trimmed == "" { |
| 2038 | return false, "", fmt.Errorf("window title cannot be empty") |
| 2039 | } |
| 2040 | |
| 2041 | if _, err := exec.LookPath("osascript"); err != nil { |
| 2042 | return false, "", fmt.Errorf("osascript not found in PATH: %w", err) |
| 2043 | } |
| 2044 | |
| 2045 | script := fmt.Sprintf(`set targetTitle to "%s" |
| 2046 | set matched to false |
| 2047 | |
| 2048 | tell application "System Events" |
| 2049 | if not (exists application process "Cursor") then |
| 2050 | return "NOT_RUNNING" |
| 2051 | end if |
| 2052 | |
| 2053 | tell application process "Cursor" |
| 2054 | repeat with w in windows |
| 2055 | set winName to "" |
| 2056 | try |
| 2057 | set winName to name of w |
| 2058 | end try |
| 2059 | |
| 2060 | if winName is targetTitle then |
| 2061 | set matched to true |
| 2062 | try |
| 2063 | set frontmost to true |
| 2064 | end try |
| 2065 | try |
| 2066 | set value of attribute "AXMain" of w to true |
| 2067 | end try |
| 2068 | try |
| 2069 | perform action "AXRaise" of w |
| 2070 | end try |
| 2071 | exit repeat |
| 2072 | end if |
| 2073 | end repeat |
| 2074 | end tell |
| 2075 | end tell |
| 2076 | |
| 2077 | if matched then |
| 2078 | tell application "Cursor" to activate |
| 2079 | return "FOCUSED" |
| 2080 | end if |
| 2081 | |
| 2082 | return "NOT_FOUND"`, escapeAppleScriptString(trimmed)) |
| 2083 | |
| 2084 | cmd := exec.Command("osascript", "-e", script) |
| 2085 | output, err := cmd.CombinedOutput() |
| 2086 | if err != nil { |
| 2087 | trimmedErr := strings.TrimSpace(string(output)) |
| 2088 | if trimmedErr != "" { |
| 2089 | return false, "", fmt.Errorf("osascript focus Cursor: %s", trimmedErr) |
| 2090 | } |
| 2091 | return false, "", fmt.Errorf("osascript focus Cursor: %w", err) |
| 2092 | } |
no test coverage detected