Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save asif-mistry/fe226a0a925cb0f2dd45092920c6c706 to your computer and use it in GitHub Desktop.
Save asif-mistry/fe226a0a925cb0f2dd45092920c6c706 to your computer and use it in GitHub Desktop.
Allows you to re-launch a Cocoa app
import Cocoa
extension NSApplication {
func relaunch(afterDelay seconds: TimeInterval = 0.5) -> Never {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", "sleep \(seconds); open \"\(Bundle.main.bundlePath)\""]
task.launch()
self.terminate(nil)
}
}
@KyLeggiero
Copy link

I've tweaked this by making the extension and function to be public, and I placed exit(0) at the end: https://gist.github.com/BenLeggiero/449fb9b1a45b69fb276f4f9ad86cab7a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment