Skip to content

Instantly share code, notes, and snippets.

@KyLeggiero
Last active April 3, 2021 13:50
Show Gist options
  • Save KyLeggiero/449fb9b1a45b69fb276f4f9ad86cab7a to your computer and use it in GitHub Desktop.
Save KyLeggiero/449fb9b1a45b69fb276f4f9ad86cab7a to your computer and use it in GitHub Desktop.
Allows you to re-launch a Cocoa app
import Cocoa
public extension NSApplication {
public 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)
exit(0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment