-
-
Save asif-mistry/c0cae7d16d9610f0e4b30ee1d753f48b to your computer and use it in GitHub Desktop.
Self relaunch of Cocoa application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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