如何提供回调以了解任务何时完成?我需要设置一个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语言是JavaScript for Automaton,这是一种用于Yosemite OS X 10.10的新的OSASCRIPT语言
发布于 2014-10-31 22:10:52
我不确定你是否已经尝试过了,但也许值得一试,看看它是否适用于你。
我认为,您可以尝试使用这两个函数中的一个。作为$.performSelector...,看看它是否适用于您..
[self performSelectorOnMainThread:@selector(myTask) withObject:nil waitUntilDone:YES];
[self performSelector:@selector(myTask) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES];我希望这会有帮助..。
https://stackoverflow.com/questions/26578795
复制相似问题