Skip navigation.
 
mlRelaunching an application
FROM : Mattias Arrelid
DATE : Mon Mar 03 17:24:17 2008

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

Related mailsAuthorDate
mlRelaunching an application Mattias Arrelid Mar 3, 17:24
mlRe: Relaunching an application Nir Soffer Mar 3, 18:14
mlRe: Relaunching an application Mattias Arrelid Mar 3, 18:18
mlRe: Relaunching an application Jean-Daniel Dupas Mar 3, 18:29
mlRe: Relaunching an application John Stiles Mar 3, 18:38
mlRe: Relaunching an application Steven Degutis Mar 3, 20:43
mlRe: Relaunching an application Michael Ash Mar 3, 23:22
mlRe: Relaunching an application Steven Degutis Mar 4, 02:48
mlRe: Relaunching an application Joe Ranieri Mar 4, 03:27
mlRe: Relaunching an application Mattias Arrelid Mar 4, 12:10
mlRe: Relaunching an application Michael Ash Mar 4, 17:11