Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created June 4, 2010 15:59
Show Gist options
  • Save mkhl/425597 to your computer and use it in GitHub Desktop.
Save mkhl/425597 to your computer and use it in GitHub Desktop.
// Restart your Cocoa application using Sparkle
// Author: Marc Charbonneau
// Source: http://blog.mbcharbonneau.com/2010/06/03/restart-your-cocoa-application-using-sparkle/
NSString *launcherSource = [[NSBundle bundleForClass:[SUUpdater class]] pathForResource:@"relaunch" ofType:@""];
NSString *launcherTarget = [NSTemporaryDirectory() stringByAppendingPathComponent:[launcherSource lastPathComponent]];
NSString *appPath = [[NSBundle mainBundle] bundlePath];
NSString *processID = [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]];
[[NSFileManager defaultManager] removeItemAtPath:launcherTarget error:NULL];
[[NSFileManager defaultManager] copyItemAtPath:launcherSource toPath:launcherTarget error:NULL];
[NSTask launchedTaskWithLaunchPath:launcherTarget arguments:[NSArray arrayWithObjects:appPath, processID, nil]];
[NSApp terminate:sender];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment