1

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!

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
richbrz
  • 92
  • 8

1 Answers1

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