Skip to content

Instantly share code, notes, and snippets.

@danmartyn
Created July 22, 2013 05:24
Show Gist options
  • Save danmartyn/6051464 to your computer and use it in GitHub Desktop.
Save danmartyn/6051464 to your computer and use it in GitHub Desktop.
This is a cocoa method for restarting a mac app
+(void)restart:(id)sender
{
NSString *restartScript = @"while ps -p $1 > /dev/null; do sleep 0.1; done; open \"$2\"";
NSArray *arguments = [NSArray arrayWithObjects:
@"-c", restartScript,
@"",
[NSString stringWithFormat:@"%d",[[NSProcessInfo processInfo] processIdentifier]],
[[NSBundle mainBundle] bundlePath],
nil];
[NSTask launchedTaskWithLaunchPath:@"/bin/sh" arguments:arguments];
[NSApp terminate:self];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment