-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
volume_darwin.go
53 lines (43 loc) · 1.22 KB
/
volume_darwin.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package volume
import (
"fmt"
"strconv"
"strings"
)
func cmdEnv() []string {
return nil
}
func getVolumeCmd() []string {
return []string{"osascript", "-e", "output volume of (get volume settings)"}
}
func parseVolume(out string) (int, error) {
out = strings.TrimSuffix(out, "\n")
if out == "missing value" {
return 0, fmt.Errorf("failed to get volume settings: %s", out)
}
return strconv.Atoi(out)
}
func setVolumeCmd(volume int) []string {
return []string{"osascript", "-e", "set volume output volume " + strconv.Itoa(volume)}
}
func increaseVolumeCmd(diff int) []string {
return []string{"osascript", "-e", "set volume output volume ((output volume of (get volume settings)) + " + strconv.Itoa(diff) + ")"}
}
func getMutedCmd() []string {
return []string{"osascript", "-e", "output muted of (get volume settings)"}
}
func parseMuted(out string) (bool, error) {
switch strings.TrimSpace(out) {
case "true":
return true, nil
case "false":
return false, nil
}
return false, fmt.Errorf("unknown muted status: %s", out)
}
func muteCmd() []string {
return []string{"osascript", "-e", "set volume output muted true"}
}
func unmuteCmd() []string {
return []string{"osascript", "-e", "set volume output muted false"}
}