Skip navigation.
 
mlReceiving app launch notification in command line tool
FROM : Ralph Pöllath
DATE : Thu Nov 25 11:45:30 2004

Hi,

is it possible to have a Cocoa command line tool launch an application
and be notified once the app is up and running?
It seems straightforward, but my tool never receives the notification.

Thanks,
-Ralph.


#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

// launcher.m
// cc -framework Cocoa launcher.m -o launcher
// based on http://www.cocoabuilder.com/archive/message/2002/6/8/58057

// problem: launchNotification: never gets called

@interface NotifTarget:NSObject
@end

@implementation NotifTarget
+ (void) launchNotification: (NSNotification *) aNotification
{
   NSLog(@"-%@ -- %@", NSStringFromSelector(_cmd), aNotification);
}
@end

int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   [[[NSWorkspace sharedWorkspace] notificationCenter]
       addObserver: [NotifTarget class]
       selector: @selector(launchNotification:)
       name: NSWorkspaceDidLaunchApplicationNotification
       object: nil];

   if(![[NSWorkspace sharedWorkspace] launchApplication:@"TextEdit"]){
       NSLog(@"app could not be launched");
   }
   else{
       NSLog(@"app was launched, now waiting for
NSWorkspaceDidLaunchApplicationNotification");
       [[NSRunLoop currentRunLoop] run];
   }

   [pool release];
   return 0;
}

Related mailsAuthorDate
No related mails found.