-
-
Save asif-mistry/fe226a0a925cb0f2dd45092920c6c706 to your computer and use it in GitHub Desktop.
Allows you to re-launch a Cocoa app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tweaked this by making the extension and function to be
public
, and I placedexit(0)
at the end: https://gist.github.com/BenLeggiero/449fb9b1a45b69fb276f4f9ad86cab7a