Re: Programmatically relaunching app
Re: Programmatically relaunching app
- Subject: Re: Programmatically relaunching app
- From: Greg Robbins <email@hidden>
- Date: Tue, 23 Mar 2004 11:04:31 -0800
>
>osascript -e 'tell application "YourAppName" to activate' # Relaunch with apple event
>
>
never tried myself, but why not to use the plain 'open' command?
You can also just execute the program itself. Doing so avoids confusing Launch Services, which can happen if you ask Launch Services to launch an already-running program.
I've used code like this:
NSString* launchScriptPath = [[NSTemporaryDirectory()
stringByAppendingPathComponent:@"MyRelaunchScript"];
NSString* script = [NSString stringWithFormat:@"\"%s\" &",
[[[NSBundle mainBundle] executablePath] fileSystemRepresentation]];
if ( [script writeToFile:launchScriptPath atomically:NO] )
{
chmod( [launchScriptPath fileSystemRepresentation], S_IRWXG | S_IRWXU ); // stat.h
NSArray* args = [NSArray arrayWithObject:launchScriptPath];
NSTask* task = [NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:args];
// the script uses '&' to detach the task being launched, so we can wait til the task is done here
[task waitUntilExit];
[[NSApplication sharedApplication] terminate:self];
return;
}
Greg Robbins
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.