2

如何提供回调以了解任务何时完成?我需要设置一个 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 语言

4

1 回答 1

2

我不确定你是否尝试过这个,但也许值得试一试,看看它是否适合你..

我认为,您可以尝试使用这两个功能之一..$.performSelector...看看它是否适合您..

[self performSelectorOnMainThread:@selector(myTask) withObject:nil waitUntilDone:YES];

[self performSelector:@selector(myTask) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES];

我希望它有帮助..

于 2014-10-31T14:10:52.257 回答