2

How do I provide a callback to know when a task has completed? Do I need to set up an NSRunLoop or something?

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 The language is JavaScript for Automaton, a new OSASCRIPT language for Yosemite OS X 10.10

JakeCigar
  • 603
  • 6
  • 12

1 Answers1

2

I'm not sure if you have tried this, but maybe is worth it to give it a shot and see if it works for you..

I think, you could try using one of these two functions.. as $.performSelector... and see if it works for you..

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

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

I hope it helps..

valbu17
  • 4,034
  • 3
  • 30
  • 41
  • Your code is written in actual Objective-C. I am writing in JavaScript for Automaton. – JakeCigar Oct 31 '14 at 16:04
  • yah, but I see that you are still using Objective-C classes..So, I'm guessing if you access to the classes you should have access to the member functions as well. – valbu17 Oct 31 '14 at 17:33
  • I’ve never written in Objective-C. I’ve seen many demos on the net. There is so little about JFA or how to deal with the objc classes. I have synchronous code working, but I am an asynchronous guy coming from a node.js world. – JakeCigar Oct 31 '14 at 17:50