This commit is contained in:
20
run_admin_darwin.go
Normal file
20
run_admin_darwin.go
Normal file
@@ -0,0 +1,20 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func runWithAdmin(exePath string, env []string) error {
|
||||
escaped := strings.ReplaceAll(exePath, `"`, `\"`)
|
||||
script := fmt.Sprintf(`do shell script "%s" with administrator privileges`, escaped)
|
||||
|
||||
cmd := exec.Command("osascript", "-e", script)
|
||||
cmd.Env = append(os.Environ(), env...)
|
||||
return cmd.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user