Mac Sandbox issues with opening embedded RTF files

68 Views Asked by At

My Mac programs usually ship with some internal Rich Text files containing legal details. I use the NSWorkspace openFile call to open the files within TextEdit.

The code looks something like this:

guard let aPath = Bundle.main.path(forResource: “Legal.rtf”, ofType: nil) else { return }
NSWorkspace.shared.openFile(aPath, withApplication: nil)

This has always worked, until recently when this code returns “The application can’t be opened. -50”. Is that a Sandbox issue? Accessing files within your bundle should be allowed. We do it for images and such.

What do I have set wrong?

Thank you!

1

There are 1 best solutions below

1
Steve Sheets On

Thank you for your comments.

I should have mentioned at first that parameter string I had included both filename and the file type (extension). So I would have to split them, something that was easy to do with NSString, but is not immediately available for Swift String. A bit of conversion would have given me the two strings.

However, that OpenFile has been replaced with the newer open(_:)

let name = "Legal.rtf"

guard let aURL = Bundle.main.url(forResource: name, withExtension: "") else { return }

NSWorkspace.shared.open(aURL)

This call does NOT mind if you pass it string with both parts.