问题
I am new on Swift and I am trying to create a very simple application that executes a root shell command when you press a round button.
I have found the following link online, that explains how to execute a shell command with user permission on swift, but it doesn't tell how to do it with root privileges: http://practicalswift.com/2014/06/25/how-to-execute-shell-commands-from-swift/
How can I do it?
回答1:
Quick-and-dirty:
NSAppleScript(source: "do shell script \"sudo whatever\" with administrator " +
"privileges")!.executeAndReturnError(nil)
Alternatively look into privileged helper tools but expect that to be much more complicated.
来源:https://stackoverflow.com/questions/26707557/how-to-execute-a-shell-command-with-root-permission-from-swift