-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathbeep_darwin.go
More file actions
32 lines (26 loc) · 772 Bytes
/
beep_darwin.go
File metadata and controls
32 lines (26 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build darwin && !linux && !freebsd && !netbsd && !openbsd && !windows && !js
package beeep
import (
"os"
"os/exec"
)
var (
// DefaultFreq - frequency, in Hz, middle A
DefaultFreq = 0.0
// DefaultDuration - duration in milliseconds
DefaultDuration = 0
)
// Beep beeps the PC speaker (https://en.wikipedia.org/wiki/PC_speaker).
//
// On macOS, it will first try to use `osascript` and will fall back to sending bell character.
// Enable `Audible bell` in Terminal --> Preferences --> Settings --> Advanced.
func Beep(freq float64, duration int) error {
osa, err := exec.LookPath("osascript")
if err != nil {
// Output the only beep we can
_, err = os.Stdout.Write([]byte{7})
return err
}
cmd := exec.Command(osa, "-e", `beep`)
return cmd.Run()
}