I am having a bit of trouble with NSTask()
in Swift (for an OS X application). Can someone post a snippet of code in Swift that uses NSTask()
correctly? Thank you!
Asked
Active
Viewed 965 times
1 Answers
4
Create a task…
let task = NSTask()
Select a path…
task.launchPath = "/usr/bin/say"
Pass any arguments to the command…
task.arguments = ["I'm Guybrush Threepwood, Mighty Pirate!"]
Launch the task, and block the current thread until it's done…
task.launch()
task.waitUntilExit()

Aaron Brager
- 65,323
- 19
- 161
- 287
-
do you have to have terminal open? – richbrz Jul 08 '15 at 22:36
-
No, you don't. Just copy and paste that code onto Playground and check the result. – Marco Almeida Dec 24 '15 at 17:11