Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save asif-mistry/c0cae7d16d9610f0e4b30ee1d753f48b to your computer and use it in GitHub Desktop.
Save asif-mistry/c0cae7d16d9610f0e4b30ee1d753f48b 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