I discovered from a Linux Mint Forum topic that what I was missing is making sure the current user had sufficient permissions (the error messages gave me no indication that it was a permission issue, but turns out, it was).
I moved the command into a Bash script named setVolume.sh
(making sure it has the correct permissions with chmod
), with the user myuser
being part of the group for /usr/bin/amixer
:
sudo su - myuser
amixer -c 3 set PCM 50%
Then, I changed Go code to:
package main
import (
"fmt"
"log"
"os"
"os/exec"
)
func main() {
setVolumeCommand := exec.Command("/bin/sh", "./setVolume.sh")
setVolumeCommand.Stdout = os.Stdout
setVolumeCommand.Stderr = os.Stderr
setVolumeError := setVolumeCommand.Run()
if setVolumeError != nil {
log.Fatal(setVolumeError)
}
}
Thanks for helping me figure this out!