osx - Close and launch with different command line parameters/arguments -


i running .app , need "restart" speak. need tell close, after closing, should launch path tell (which itself) command line arguments. possible cocoa? im getting stuck @ part app closing closed, cant back.

my code in js-ctypes, here objc pseudo code:

default_center = [nsdistributednotificationcenter defaultcenter]; shared_workspace = [nsworkspace sharedworkspace]; notification_center = [[nsworkspace sharedworkspace] notificationcenter]; [notification_center addobserver:selector:name:object: ***, ***, nsworkspacedidlaunchapplicationnotification, nil] 

and in observr when responds completion of quit has code launch. app closed never gets observer responder. here

thanks

you didn't mention reason cannot launch second instance of app first instance, rather chicken & egg approach of trying restart after you've quit... have code in appwillterminate function have situation yours:

    [[nsworkspace sharedworkspace] launchapplicationaturl:appurl options:nsworkspacelaunchnewinstance configuration:nil error:&error]; 

( appwillterminate called in first place, had disablesuddentermination before calling [app quit] )

there's flag in app's plist file "allow multiple instance" or something.

also, know this: if app sandboxed, not work unless code signed applestore given id, or developer id application id. also, won't work on x.7 no matter what, when sandboxed.

method two,

is create "helper app". killerapp goes through quit process, , right before dies, launches "helperapp", tiny command line tool waits killerapp die, relaunches it.

in xcode, code helperapp, "command line tool", this:

#import <cocoa/cocoa.h>   int main( int argc , char *argv[] ) {  nsautoreleasepool*  pool = [[nsautoreleasepool alloc] init];  pid_t parentpid = atoi(argv[2]); processserialnumber psn;  while ( getprocessforpid(parentpid, &psn) != procnotfound )     sleep(1);  nsstring*   apppath = [nsstring stringwithcstring:argv[1] encoding:nsutf8stringencoding]; bool        success = [[nsworkspace sharedworkspace] openfile:[apppath stringbyexpandingtildeinpath]];  if ( ! success )     nslog(@"error: not relaunch application @ %@", apppath);  [pool drain];  return (success) ? 0 : 1; } 

as can see, call helperapp couple parameters killerapp... , in case don't need sandboxed, that's it.

if need sandboxing, gets more complicated, of course. need create "privileged helper tool", , thank goodness there sample code it.

"smjobbless" apple sample code project outlines how this, it's kind of weird-- doesn't anything. thankfully, took project , created "smjobblessxpc" it, finish job, ( , when working, killerapp can communicate helperapp ). downside need maintain plist files of 2 apps in terms of code signing.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -