Skip to content

Instantly share code, notes, and snippets.

@cdfmr
Created March 26, 2012 11:56
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cdfmr/2204627 to your computer and use it in GitHub Desktop.
Save cdfmr/2204627 to your computer and use it in GitHub Desktop.
Self relaunch of Cocoa application
@implementation NSApplication (Relaunch)
- (void)relaunchAfterDelay:(float)seconds
{
NSTask *task = [[[NSTask alloc] init] autorelease];
NSMutableArray *args = [NSMutableArray array];
[args addObject:@"-c"];
[args addObject:[NSString stringWithFormat:@"sleep %f; open \"%@\"", seconds, [[NSBundle mainBundle] bundlePath]]];
[task setLaunchPath:@"/bin/sh"];
[task setArguments:args];
[task launch];
[self terminate:nil];
}
@end
@kerker00
Copy link

@nAviram
Copy link

nAviram commented May 21, 2015

how do u start it?

@bikram990
Copy link

bikram990 commented Jul 13, 2017

I'm using this but for me Its opening terminal while relaunching.

@KyLeggiero
Copy link

KyLeggiero commented Jul 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment