I'm trying to get a button in Xcode to run a shell script with clicked.
This works
@IBAction func test(_ sender: NSButton) {
let path = "/usr/bin/say"
let arguments = ["hello world"]
sender.isEnabled = false
let task = Process.launchedProcess(launchPath: path, arguments: arguments)
task.waitUntilExit()
sender.isEnabled = true
}
But when I try this it does not work to run a script from the Desktop
@IBAction func test(_ sender: NSButton) {
let path = "/bin/bash"
let arguments = ["~/Desktop/test.sh"]
sender.isEnabled = false
let task = Process.launchedProcess(launchPath: path, arguments: arguments)
task.waitUntilExit()
sender.isEnabled = true
}
I get this error output in Xcode
/bin/bash: ~/Desktop/test.sh: No such file or directory
If anyone can help me with some help or example that would great. Thank you.
~as home dir. Try the full absolute path