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 |
This comment has been minimized.
This comment has been minimized.
how do u start it? |
This comment has been minimized.
This comment has been minimized.
I'm using this but for me Its opening terminal while relaunching. |
This comment has been minimized.
This comment has been minimized.
Swift 4 version: https://gist.github.com/BenLeggiero/449fb9b1a45b69fb276f4f9ad86cab7a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Swift version if you need https://gist.github.com/kerker00/63d52c7b0e6a5df1d2bc