I'm trying to build a MacOS app that can run bash commands from GUI input and have fallen at the first hurdle. I've been using this question's answer as a reference but it doesn't seem to work for me. This is my code:
import Foundation
@IBAction func buttonClicked(_ sender: Any) {
shell("ls")
}
@discardableResult
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/Users/myUser/desktop"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
I've seen others asking about this error but they are getting it for slightly different reasons meaning I can't seem to find a fix for my particular instance of the problem.
Any ideas?
EDIT - Would also be great if someone could give me a hint as to how to get the output of the ls command back into my program, to store as a string for example.