Perhaps a small application like relaunch.app could be imbedded into your relaunchable application, where all it pretty much does is serve as a buffer by relaunching your application reliably (through Cocoa methods) after your app calls it the same way you mentioned above.
[[NSWorkspace sharedWorkspace] launchApplication:relauncherExecutablePath]; [NSApp terminate:self]; Then the relaunch.app program uses a method which calls itself continuously (like a loop that wont make your app unresponsive), which does a check to see if the original app is still running using NSWorkspace's -launchedApplications, and only after it sees your app end, then it will run the app again and terminate itself. This ensures that your app opens only after it ends first. And doing this would be quite easy, using two methods, -awakeFromNib and your custom method -hasAppEnded. The former would launch the second one immediately, and do nothing else, and the second one would do the check, and at the end, if it is still running (hasnt quit and run the new app) it would launch itself with [self performSelector:@selector(hasAppEnded) withObject:nil afterDelay:1.0]; or something. This is what I would do anyway. 1.0 might be too long or too short for a real application, though. On Mon, Mar 3, 2008 at 10:24 AM, Mattias Arrelid <[EMAIL PROTECTED]> wrote: > Hi everyone, > > I have an application that I need to restart. An easy way to do this > could be: > > [[NSWorkspace sharedWorkspace] launchApplication:executablePath]; > [NSApp terminate:self]; > > The problem is that the above solution results in confusion in the > system dock; sometimes the original application does manage to quit > before the new instance, other times not. If it does NOT manage to > quit before the new one is launched, the dock ends up with two icons > for my application; one that indicates that the application is > launched, another one that's indicates that it's not launched. This is > NOT good. > > I've seen other programs in need of a restart (e.g. the Sparkle > framework) using a separate helper application that simply checks > whether the original process has quit properly before re-launching it. > This sure does work, but it isn't a pretty solution. > > Another solution could be something like: > > system("nohup sh -c 'sleep 1; open -b com.company.identifier'"); > exit(0); > > This is (in my humble opinion) better, but still, not very elegant. > > Wouldn't it be nice if we could have something like [NSApp relaunch], > [NSApp relaunchWithArguments:argArray] etc. to deal with stuff like > this? Or does such calls imply things that I'm overseeing right now? > Maybe there are similar methods already available in the system, that > accomplishes stuff like this? > > Any ideas/suggestions on the above are more than welcome. > > Thanks in advance. > Mattias > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/sephknows%40gmail.com > > This email sent to [EMAIL PROTECTED] > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]