vendor/github.com/gen2brain/beeep/beep_darwin.go
29 lines · 655 bytes
1//go:build darwin && !linux && !freebsd && !netbsd && !openbsd && !windows && !js
2// +build darwin,!linux,!freebsd,!netbsd,!openbsd,!windows,!js
3
4package beeep
5
6import (
7 "os"
8 "os/exec"
9)
10
11var (
12 // DefaultFreq - frequency, in Hz, middle A
13 DefaultFreq = 0.0
14 // DefaultDuration - duration in milliseconds
15 DefaultDuration = 0
16)
17
18// Beep beeps the PC speaker (https://en.wikipedia.org/wiki/PC_speaker).
19func Beep(freq float64, duration int) error {
20 osa, err := exec.LookPath("osascript")
21 if err != nil {
22 // Output the only beep we can
23 _, err = os.Stdout.Write([]byte{7})
24 return err
25 }
26
27 cmd := exec.Command(osa, "-e", `beep`)
28 return cmd.Run()
29}