Skip to content

Instantly share code, notes, and snippets.

@mminer
Created May 2, 2017 19:49
Show Gist options
  • Save mminer/2c5ab47a45f5172e5793353888c1687b to your computer and use it in GitHub Desktop.
Save mminer/2c5ab47a45f5172e5793353888c1687b to your computer and use it in GitHub Desktop.
Extension function to restart a Cocoa application.
import AppKit
extension NSApplication {
/// Restarts the application.
func restart() {
let process = Process()
process.launchPath = "/bin/sh"
process.arguments = ["-c", "sleep 1; open '\(Bundle.main.bundlePath)'"]
process.launch()
terminate(nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment