0

Hey guys here is what I want but have no idea how I could do it.

It's a simple thing but just can't figure out how I could click on a button and execute command directly on Terminal.

Explaining better, I have a textView and a button (Cocoa). So, when I click the button it will trigger a sudo -s then will execute another command with arguments.

So, anyone could help?

Marco Almeida
  • 1,285
  • 3
  • 17
  • 39
  • You can have a look at [NSTask](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/index.html#//apple_ref/occ/cl/NSTask) to execute in a terminal. – Eric Aya May 07 '15 at 18:09
  • Executing a command is simple with NSTask (and you should find many examples on SO. [Here](http://stackoverflow.com/a/29549342/1187415) is an example how to execute a tool *asynchronously*, so that the UI is not blocked. – Executing a privileged command is more complicated. Look for Authorization Services and SMJobBless ... – Martin R May 07 '15 at 18:10
  • Ok, but still that answer you posted is too complicated to me. Using that code, how could I execute just a "ls"command and get the response on the console or textView? – Marco Almeida May 07 '15 at 18:24
  • What about this one: http://stackoverflow.com/a/29519615/1187415 ? – Martin R May 07 '15 at 18:26
  • Sorry Martin, looked at the new link you posted but still can't figure out how I could do an "ls" on a path I set. I tried this: let output = runCommand("/Users/home/Documents/", args: "ls").output println(output) And this: let output = runCommand("/Users/home/Documents/ls", args: "").output println(output) – Marco Almeida May 07 '15 at 18:36
  • 1
    Oh I got it!!! let output = runCommand("/bin/ls", args: "/Users/home/Documents/").output println(output) Martin you should answer this question with the code from the link and then I will mark it as the correct answer. – Marco Almeida May 07 '15 at 18:42

0 Answers0