Restarting OSX app programmatically
I need to restart my app in case I reload something that will require a start from the very beginning. I tried this
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent let task = NSTask() task.launchPath = "open" task.arguments = [path] task.launch() exit(0)
but I get an error upon the
launch path not accessible
- OSX: changing path of .framework
- What is 'llvm-gcc-4.2' doing in '/usr' on my Yosemite system?
- OSX CoreData: issue only for some entities: +entityForName: could not locate an entity named 'myEntity' in this model
- Xcode building and resources folders
- OSX status menu not working in Swift
- Get Serial Number of USB HDD (Mac OS)
Solutions Collect From Internet About “Restarting OSX app programmatically”
Though the problem itself was trivial (forgot the path) I leave question and answer in case someone else needs the same functionality.
let path = NSBundle.mainBundle().resourcePath!.stringByDeletingLastPathComponent.stringByDeletingLastPathComponent let task = NSTask() task.launchPath = "/usr/bin/open" task.arguments = [path] task.launch() exit(0)
Edit (daily Swift syntax change for Sw3):
let url = URL(fileURLWithPath: Bundle.main.resourcePath!) let path = url.deletingLastPathComponent().deletingLastPathComponent().absoluteString let task = Process() task.launchPath = "/usr/bin/open" task.arguments = [path] task.launch() exit(0)
- Cannot open storyboard (com.apple.InterfaceBuilder error -1.)
- How to know which line of plist file is incorrect
- Typical time for Waiting For Review?
- how to change the scale of view
- The Completest Cocos2d-x Tutorial & Guide List
- Change highlighting color in NSTableView in Cocoa?
- iOS slide up an image over an image, revealing the underneath one. (A-la jQuery.slide())
- Autoscrolling infinite effect in .linear type of iCarousel in swift
- How can I delete object from core data in swift 3
- Show more button next to end of text Swift
- Array retuning a blank array outside of PFQuery with Parse.
- Keep iphone active while running program
- Is it possible to add custom text in NSDateFormatter's format string?
- IPhone Bluetooth Connectivity to Non IOS Devices
- SpriteKit Swift Node Count issues