I am building a cocoa app in Xcode that uses buttons to execute MacOS shell scripts. The code I am using for Button1 is:
@IBAction func Button1(_ sender: NSButton) {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/Users/myusername/Desktop/shellscript.command")
try? process.run()
This works perfectly but its not a permanent solution because I'm relying on the fact that the files are on the Desktop of my mac, not actually inside of Xcode. I already added a Resources folder and put shellscript.command inside but Xcode isn't recognizing when I try to access it. Here is what I tried to no avail:
@IBAction func Button1(_ sender: NSButton) {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/Resources/shellscript.command")
try? process.run()
I would really appreciate if someone could share very specifically the the right code to use to access files stored inside the resources folder in a cocoa app project (in other words, what the url is to directly reference resources). I looked on dozens of other stackoverflow posts but couldn't seem to find the answer. Thank you