Skip to content

Instantly share code, notes, and snippets.

@arufian
Forked from cdfmr/NSApplication+SelfRelaunch.m
Created November 27, 2012 02:13
Show Gist options
  • Save arufian/4151972 to your computer and use it in GitHub Desktop.
Save arufian/4151972 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment