Created
March 26, 2012 11:56
-
-
Save cdfmr/2204627 to your computer and use it in GitHub Desktop.
Self relaunch of Cocoa application
This file contains 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 |
how do u start it?
I'm using this but for me Its opening terminal while relaunching.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift version if you need https://gist.github.com/kerker00/63d52c7b0e6a5df1d2bc