0

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

infinitedev108
  • 21
  • 1
  • 1
  • 3
  • https://developer.apple.com/documentation/foundation/bundle/1411540-url, https://stackoverflow.com/q/37580015/1187415. – Martin R Mar 14 '20 at 07:45
  • Does this answer your question? [How to access file included in app bundle in Swift?](https://stackoverflow.com/questions/37580015/how-to-access-file-included-in-app-bundle-in-swift) – Willeke Mar 14 '20 at 11:41

0 Answers0