如何提供回调来了解任务何时完成?我需要设置 NSRunLoop 之类的吗?
ObjC.import('Cocoa');
exec("/usr/bin/say",["hello"])
function done(notification) {
$.NSLog('Application done');
$.NSLog(notification);
}
function exec(cmd,args){
var task = $.NSTask.alloc.init
task.launchPath=cmd
task.arguments=args
task.terminationHandler = $(done) // does not work!
task.launch
$.NSLog("running: "+task.running)
return task
}
PS 该语言是 Automaton 的 JavaScript,这是 Yosemite OS X 10.10 的新 OSASCRIPT 语言
最佳答案
我不确定您是否尝试过此操作,但也许值得尝试一下,看看它是否适合您..
我认为,您可以尝试使用这两个函数之一..作为 $.performSelector...
并看看它是否适合您..
[self performSelectorOnMainThread:@selector(myTask) withObject:nil waitUntilDone:YES];
[self performSelector:@selector(myTask) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES];
希望对您有帮助。
关于javascript - NS任务完成情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26578795/