I want be able to run this code through Swift for Terminal in macOS:
cd ~/Desktop/
mkdir "New Folder"
Basically I want to go to level of desktop then create a new Folder there. I want press a button in Swift/SwiftUI to run a function to execute the code for Terminal. Using Swift/SwiftUI is just for UI. I do not have shell file saved some where, all my codes is that I want be able to run those 2 commands for Terminal from Swift.
func runBashCode() {
// need help here
cd ~/Desktop/
mkdir "New Folder"
}
try something like this:
Note: you need to delete the "App Sandbox" in the "Signing & Capabilities"
struct ContentView: View {
let arg = NSHomeDirectory() + "/Desktop/newfolder"
var body: some View {
Button("mkdir") {
runMkdir()
}.frame(width: 333, height: 333)
}
func runMkdir() {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/bin/mkdir")
task.arguments = [arg]
task.launch()
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments