Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@kerker00 kerker00 commented Jul 28, 2014

@nAviram

This comment has been minimized.

Copy link

@nAviram nAviram commented May 21, 2015

how do u start it?

@bikram990

This comment has been minimized.

Copy link

@bikram990 bikram990 commented Jul 13, 2017

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

@BenLeggiero

This comment has been minimized.

Copy link

@BenLeggiero BenLeggiero commented Jul 13, 2017

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