So I have this button that lets me run /usr/bin/say in the terminal, which works just fine. But when I try to change the executableURL variable, so I run sudo nano /private/etc/hosts instead, I get this error
So my question is, how can I access the terminal through my macOS app and run sudo nano /private/etc/hosts?
Button(action: {
let executableURL = URL(fileURLWithPath: "/usr/bin/say")
// let executableURL = URL(fileURLWithPath: "sudo nano /private/etc/hosts")
self.isRunning = true
do {
try Process.run(executableURL,
arguments: ["Hello World"],
terminationHandler: { _ in self.isRunning = false })
} catch{
print(error)
}
}) {
Text("Say")
}
EDIT:
By using this arguments arguments: ["-c", "echo myPassword | sudo -S -- sh -c \"echo \"127.0.0.1www.apple.com \" >> /etc/hosts\""]
line and this path URL(fileURLWithPath: "/bin/zsh") I was able to append to the hosts file.
A problem that I'm having is that I was able to append the things you see in the picture(not line 1) but for some reason nothing is appended anymore when I try to do the same as before. Which is a big problem. I think I have to create a new line after appending something. Any ideas on how to do this?
