MCPcopy Index your code
hub / github.com/nikivdev/go / safariFrontmostURL

Function safariFrontmostURL

cli/flow/main.go:2534–2560  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2532}
2533
2534func safariFrontmostURL() (string, error) {
2535 script := `tell application "System Events"
2536 set safariRunning to (name of processes) contains "Safari"
2537end tell
2538if not safariRunning then error "Safari is not running"
2539tell application "Safari"
2540 if not (exists front document) then error "Safari has no front document"
2541 return URL of front document
2542end tell`
2543
2544 cmd := exec.Command("osascript", "-e", script)
2545 output, err := cmd.CombinedOutput()
2546 if err != nil {
2547 trimmed := strings.TrimSpace(string(output))
2548 if trimmed != "" {
2549 return "", fmt.Errorf("osascript: %s", trimmed)
2550 }
2551 return "", fmt.Errorf("osascript failed: %w", err)
2552 }
2553
2554 url := strings.TrimSpace(string(output))
2555 if url == "" {
2556 return "", fmt.Errorf("front Safari tab URL is empty")
2557 }
2558
2559 return url, nil
2560}
2561
2562type commitPayload struct {
2563 message string

Callers 1

runYoutubeToSoundFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected