I want to be notified when an application is started on Mac OSX. I found Cocoa Application Finished Launch and that seemed to answer my question, but the callback method appDidLaunch
is not being called when Preview get's launched.
Here's what I have so far,
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
@interface test_case: NSObject
-(void)run;
@end
@implementation test_case: NSObject
- (void)appDidLaunch:(NSNotification*)note
{
NSLog(@"app launched: %@", [note userInfo]);
}
-(void)run {
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];
[[NSWorkspace sharedWorkspace] openFile:@"/Users/nah/Desktop/bsd_hacks.pdf"
withApplication:@"Preview"];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
test_case * t = [[test_case alloc] init];
[t run];
}
return 0;
}
So why is appDidLaunch
not being called?