How to execute a shell command with root privileges from swift

I am new to Swift, and I am trying to create a very simple application that executes the root shell command when a round button is pressed.

I found the following link on the Internet explaining how to execute a shell command with user privileges on swift, but it does not say how to do this with root privileges: http://practicalswift.com/2014/06/25/how-to -execute-shell-commands-from-swift /

How can i do this?

+4
source share
1 answer

Quick and dirty:

NSAppleScript(source: "do shell script \"sudo whatever\" with administrator " +
    "privileges")!.executeAndReturnError(nil)

Alternatively, look at privileged helper tools, but expect this to be much more complicated.

+5

All Articles