Answer the question
In order to leave comments, you need to log in
Root for Golang - programs?
Hello everyone)
I am writing a mini-application in Go for myself.
For the GUI, I use the Fyne framework.
The essence of the question: is it possible to make my application perform actions that require superuser rights (for example, edit files like hosts)?
Well, I would like it to pop up a window like this:
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
To execute a system command in Go use os/exec
/usr/bin/osascript to pop up a window in osx
Try something like
package main
import (
"os/exec"
...
)
func main(){
...
//Чтобы получить приглашение в консоли
cmd := exec.Command("sudo", "su")
err := cmd.Run()
if err != nil {
fmt.Printf("%s", err)
}
...
//Или чтобы выпало окошко
out, err := exec.Command("osascript", "-e", "do shell script /path/to/myscript with administrator privileges").Output()
if err != nil {
fmt.Printf("%s", err)
}
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question