我正在使用工具栏按钮来控制简单的NSTask。当IBAction由常规按钮给出时,下面的代码按预期工作,但是当由NSToolbarItem给出时产生伪像。更准确地说,运行按钮不会被禁用。任何想法都将不胜感激。
import Cocoa
class Document: NSDocument {
override var windowNibName: String? {
return "Document"
}
@IBOutlet var runButtonOutlet: NSToolbarItem! // works for NSButton
@IBAction func runButtonAction(sender: AnyObject) {
runTask()
runButtonOutlet.enabled = false
}
@IBAction func quitButtonAction(sender: AnyObject) {
bigTask.terminate()
runButtonOutlet.enabled = true
}
var bigTask = NSTask()
func runTask () {
let task = NSTask()
bigTask = task
task.launchPath = "/usr/bin/say"
task.arguments = ["say something"]
task.terminationHandler = {
task in
self.runButtonOutlet.enabled = true
}
task.launch()
}
}