Skip to content

Instantly share code, notes, and snippets.

@cdfmr
Created March 26, 2012 11:56

Revisions

  1. cdfmr created this gist Mar 26, 2012.
    16 changes: 16 additions & 0 deletions NSApplication+SelfRelaunch.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    @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