1

I am building a simple app with a TextField input. I want to pass the input of the TextField to a cli tool I built with Golang.

This cli-tool is not sitting in /usr/bin but under ~/go/bin in my user directory. So, when I try something like the answer to this question it's not able to find the executable.

I tried copying the executable in every single folder of the Application but I am still getting the same error.

Where exactly am I supposed to copy the executable? What does the code from this looks like after I copied it over?

6
  • @matt are you sure it's the right link? I don't see any mention about PATH there. The problem comes with executables outside of /usr/bin. If I pass in /usr/bin/ls for example everything is fine. But if I instead pass /Users/John/go/bin/myclitool that doesn't work Commented Apr 7, 2022 at 19:47
  • Are you sandboxed? Commented Apr 7, 2022 at 20:05
  • Yes, I am running sandboxed. I want to bundle the executable into the app Commented Apr 8, 2022 at 7:54
  • You do? Then why are we talking about /usr/bin and things like that??? Commented Apr 8, 2022 at 11:36
  • Because if I execute commands from /usr/bin or for instance /bin/pwd, no complains. But if I point to my local executable /Users/John/bin/myclitool it complains Commented Apr 8, 2022 at 20:15

2 Answers 2

1

Apple provides documentation for this very thing.

Bouncing off @gallivantingitalian 's answer you may find the Bundle.main.url(forAuxiliaryExecutable:) command helpful if following Apple’s documentation.

let process = Process()
guard let url = Bundle.main.url(forAuxiliaryExecutable: "my_awesome_tool") else {
    throw AppErrors.appConfigError(reason: "my_awesome_tool tool not found")
}
process.executableURL = url
Sign up to request clarification or add additional context in comments.

Comments

0

For future reference this worked:

Step 1: embed the binary in the build (Adding resource files to xcode). To open the project tab just double click on your app root in XCode

Step 2: You will find the path to your executable like this:

let bundle = Bundle.main
let pathToExecutable = bundle.url(forResource: "myclitool", withExtension: "")

and then you can use Process to run it (e.g. How to launch an external Process?)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.