File does not exist error - but it does

I'm a hobbyist and I'm trying to convert a shell script into a compiled MacOS SwiftUI app. It requires running a third party utility that I placed in /usr/local/bin.

I found example code on the web that runs the /usr/bin/say command. It works just fine, but when I modify it to try to run the utility in /usr/local/bin, I receive a file does not exist error.

Assuming it was some sort of permissions problem, I modified the permissions on /usr/local/bin to 777, and still get the error. I searched in the Mac's Security and Privacy and added Xcode to the Developer Tools to allow it run run software that does not meet the system's security policy. Nope. I've even copied the /usr/bin/say command over to /usr/bin/local and get the same error.

I get the error on both the latest Big Sur Xcode and on the latest beta Monterey and Xcode beta.

Could someone please point me the docs that explain what is happening here? Thanks.

Here's the error that I'm getting: SayThis/ContentView.swift:38: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=4 "The file “say” doesn’t exist." UserInfo={NSFilePath=/usr/local/bin/say}

(lldb) 

Answered by Ken Chung in 682175022

By default, macOS apps built on Xcode are sandboxed. This means they can only access the data within the app directory.

You can either disable sandbox capability in the Signing & Capabilities tab or bundle the executable in your app.

Accepted Answer

By default, macOS apps built on Xcode are sandboxed. This means they can only access the data within the app directory.

You can either disable sandbox capability in the Signing & Capabilities tab or bundle the executable in your app.

File does not exist error - but it does
 
 
Q