(appName string)
| 1980 | } |
| 1981 | |
| 1982 | func listApplicationWindows(appName string) ([]string, error) { |
| 1983 | script := `on run argv |
| 1984 | set appName to item 1 of argv |
| 1985 | tell application "System Events" |
| 1986 | if not (exists application process appName) then |
| 1987 | error "Application '" & appName & "' is not running." |
| 1988 | end if |
| 1989 | set rawWindowNames to name of every window of application process appName |
| 1990 | end tell |
| 1991 | |
| 1992 | set filteredNames to {} |
| 1993 | repeat with winName in rawWindowNames |
| 1994 | if winName is not missing value and winName is not "" then |
| 1995 | copy (winName as text) to end of filteredNames |
| 1996 | end if |
| 1997 | end repeat |
| 1998 | |
| 1999 | if filteredNames is {} then |
| 2000 | return "" |
| 2001 | end if |
| 2002 | |
| 2003 | set AppleScript's text item delimiters to "\n" |
| 2004 | return filteredNames as text |
| 2005 | end run` |
| 2006 | |
| 2007 | cmd := exec.Command("osascript", "-", appName) |
| 2008 | cmd.Stdin = strings.NewReader(script) |
| 2009 | output, err := cmd.CombinedOutput() |
| 2010 | if err != nil { |
| 2011 | trimmed := strings.TrimSpace(string(output)) |
| 2012 | if trimmed != "" { |
| 2013 | return nil, fmt.Errorf("osascript list windows: %s", trimmed) |
| 2014 | } |
| 2015 | return nil, fmt.Errorf("osascript list windows: %w", err) |
| 2016 | } |
| 2017 | |
| 2018 | trimmed := strings.TrimSpace(string(output)) |
| 2019 | if trimmed == "" { |
| 2020 | return nil, nil |
| 2021 | } |
| 2022 | |
| 2023 | rawTitles := strings.Split(trimmed, "\n") |
| 2024 | var titles []string |
| 2025 | for _, title := range rawTitles { |
| 2026 | candidate := strings.TrimSpace(title) |
| 2027 | if candidate == "" { |
| 2028 | continue |
| 2029 | } |
| 2030 | titles = append(titles, candidate) |
| 2031 | } |
| 2032 | return titles, nil |
| 2033 | } |
| 2034 | |
| 2035 | func focusCursorWindowByTitle(title string) (bool, string, error) { |
| 2036 | trimmed := strings.TrimSpace(title) |
no outgoing calls
no test coverage detected