There is now an official article on developer.apple.com
, titled “Embedding a Command-Line Tool in a Sandboxed App.”
https://developer.apple.com/documentation/xcode/embedding-a-helper-tool-in-a-sandboxed-app
Here are the relevant steps to do (copied from the article), after you build your command line tool.
Create an entitlements file for the tool:
% /usr/libexec/PlistBuddy -c "Add :com.apple.security.app-sandbox bool true" "ToolC.entitlements"
File Doesn't Exist, Will Create: ToolC.entitlements
% /usr/libexec/PlistBuddy -c "Add :com.apple.security.inherit bool true" ToolC.entitlements
% cat ToolC.entitlements
…
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
Sign the tool as shown below:
% codesign -s - -i com.example.apple-samplecode.AppWithTool.ToolC -o runtime --entitlements ToolC.entitlements -f ToolC
...
Add the ToolC executable to your Xcode project. When you do this:
- Enable “Copy items if needed”.
- Select “Create groups” rather than “Create folder reference”.
- Uncheck all the boxes in the “Add to targets” list.
In the Build Phases tab of the app target editor, add ToolC to the Embed Helper Tools build phase, making sure that Code Sign On Copy is checked.