This is a Go language package for controlling audio volume.
brew install itchyny/tap/volume
go install github.com/itchyny/volume-go/cmd/volume@latest
$ # Get the current audio volume.
$ volume get
20
$ # Set the audio volume.
$ volume set 40
$ volume status
volume: 40
muted: false
$ # Increase/decrease the audio volume.
$ volume get
40
$ volume up
$ volume get
46
$ volume down
$ volume get
44
$ # Get current audio volume status.
$ volume status
volume: 20
muted: false
$ # Mute and unmute.
$ volume mute
$ volume status
volume: 20
muted: true
$ volume unmute
$ volume status
volume: 20
muted: false
package main
import (
"fmt"
"log"
"github.com/itchyny/volume-go"
)
func main() {
vol, err := volume.GetVolume()
if err != nil {
log.Fatalf("get volume failed: %+v", err)
}
fmt.Printf("current volume: %d\n", vol)
err = volume.SetVolume(10)
if err != nil {
log.Fatalf("set volume failed: %+v", err)
}
fmt.Printf("set volume success\n")
err = volume.Mute()
if err != nil {
log.Fatalf("mute failed: %+v", err)
}
err = volume.Unmute()
if err != nil {
log.Fatalf("unmute failed: %+v", err)
}
}
Report bug at Issues・itchyny/volume-go - GitHub.
itchyny (https://github.com/itchyny)
This software is released under the MIT License, see LICENSE.