notify.go

 1package notify
 2
 3import (
 4	"fmt"
 5	"os/exec"
 6	"runtime"
 7)
 8
 9// Send delivers a desktop notification with the given title and body.
10// On macOS it uses osascript; on Linux it uses notify-send.
11func Send(title, body string) error {
12	switch runtime.GOOS {
13	case "darwin":
14		script := fmt.Sprintf(`display notification %q with title %q sound name "default"`, body, title)
15		return exec.Command("osascript", "-e", script).Run() //nolint:noctx
16	case "linux":
17		return exec.Command("notify-send", title, body).Run() //nolint:noctx
18	default:
19		return nil
20	}
21}