Include Command Line App in Your macOS Application
Building a Command Line App
Creating a command line app is really simple. It’s just a binary so you can’t bundle resources or frameworks. You can link frameworks with a path (maybe something like ../../Frameworks inside your app bundle), but that can be fragile in case someone moves your binary and it breaks the paths. I generally make command line tools call to the main app or statically link any shared code to avoid this.
First, you’ll need a new target. Simply choose the “Command Line Tool” macOS template. Now put whatever you want in this target. To print things to Terminal, simply use print in Swift. Easy enough.
Bundling Your App
In your command line tool’s target, change “Skip Install” to “Yes”. This will ensure your archive contains only a Mac app since we are going to bundle it ourself. If you don’t do this, you won’t be able to upload your archive to the App Store, sign for Developer ID, etc.
Next, in your Mac app, add the command line tool as one of the “Target Dependencies”. Create a “New Copy Files Phase” and name it something like “Embed Command Line Tool”. Set the destination of the copy phase to “Shared Support”. Now click the + under the file list in the phase and select your binary from the “Products” group in your project. That’s it!
Now when you build your app, the command line tool will automatically be built and copied into your bundle. You could provide some UI for copying it or updating their path to include it for the user.
https://soffes.blog/bundle-command-line-tool-in-macos-app