Loading a local .scpt file in my Swift project causes error

I’m testing out a Mac app, trying to load my hello.scpt file which is in my Xcode project in the /scripts directory

# even though it's in the scripts folder, `path` will be nil unless the resource value is "hello"
let path = Bundle.main.path(forResource: "hello", ofType: "scpt")
let url = URL(fileURLWithPath: path!)
let scriptObject = try? NSUserAppleScriptTask(url: url)
scriptObject?.execute { handler in


Optional(Error Domain=NSCocoaErrorDomain Code=257 "The file
“hello.scpt” couldn’t be opened because you don’t have permission to
view it."
NSLocalizedFailureReason=Script file is not in the application scripts

I tried vadian’s response below, creating a folder called NSApplicationScriptsDirectory which seems weird. Also tried specifying in the Info.plist NSApplicationScriptsDirectory as the key and different variants to the ./scripts/ file as the key but no luck here.

This is a simple sandboxed app with a Hello World script that just prints "Hello world" to stdout

How can I load this AppleScript in and get it to work without the error?


Edit: I’ve also tried putting it in my ~/Library/Scripts folder as hello.scpt but that doesn’t work either

Source: Swift Questions