I'm trying to lunch terminal window and go to some local path in it:
my code:
public class func openShell(at url: URL?) {
guard let url = url else { return }
let shellProcess = Process();
shellProcess.launchPath = url.path;
//shellProcess.arguments = [
// "osascript -e 'tell application \"terminal\" to do script \"cd \(url)\"'"
//];
shellProcess.launch();
}
but as result there is some output into debug console inside of XCode but no shell window is opened.
commented code - alternative way that I have tried
Answer is simple:
@available(OSX 10.15, *)
public class func openTerminal(at url: URL?){
guard let url = url,
let appUrl = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.Terminal")
else { return }
NSWorkspace.shared.open([url], withApplicationAt: appUrl, configuration: NSWorkspace.OpenConfiguration() )
}
on each func call will be opened the new instance of the Terminal with selected location.
And no need to make XPC service or turn off sandbox for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With