Alex Rivera | Logout

NSRunningApplication 'terminated' not Observable

Asked 2010-11-08T20:57:45.753
14

I'm building a program that launches another program and is then supposed to monitor it, and take action if it terminates. When the application is launched, I can get an instance of NSRunningApplication from NSWorkspace.

Now, the documentation states that NSRunningApplication has the property 'terminated' that is key-value observable. I've tried implementing:

[browserInstance addObserver:self 
                          forKeyPath:@"terminated"
                             options:NSKeyValueObservingOptionNew
                             context:NULL];

And:

- (void)observeValueForKeyPath:(NSString *)keyPath 
                      ofObject:(id)object 
                        change:(NSDictionary *)change
                       context:(void *)context  
{  

        NSLog(@"observeValueForKeyPath");  
        if ([keyPath isEqual:@"terminated"])  
        {  
            NSLog(@"terminated");  
        }  
} 

but I never see the observeValueForKeyPath method get tripped. Does anyone know how to make this work, if it is possible? I haven't been able to find any specific examples anywhere online.

Edit
Report

1 Answer

0

Take a look at Apple's Technical Note 2050: Observing Process Lifetimes Without Polling.

TN2050 covers Apple's recommended methods for observing the lifetime of processes you launch, and those launched by others.

answered 2011-01-23T21:30:07.063

Your Answer