Last active
April 3, 2021 13:50
-
-
Save KyNorthstar/449fb9b1a45b69fb276f4f9ad86cab7a to your computer and use it in GitHub Desktop.
Allows you to re-launch a Cocoa app
This file contains hidden or 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 | |
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