I need to accomplish following three things. I am not sure how to go about it using Swift and Xcode
Package an existing CLI tool with the APP.
Use swift to issue commands to this CLI app and let it do its thing.
Read the output stream coming from the CLI app in real-time if possible.
I have found NSTask that should be utilized, but I get App Previlege Issues and errors. SMJobBless sounds helpful but I am having hard time to understand all this. All I was trying to do was issuing some commands to a cli app that is already embedded within my app package.
If you are looking to package a Command Line Tool you already wrote and have it run as root, that it is possible to do by installing it with
SMJobBless
but it's going to involve a bit of work. When installing a Command Line Tool in this manner, Apple refers to it as a helper tool. (Sometimes a privileged helper tool.)For
SMJobBless
to succeed, Apple requires the following:Contents/Library/LaunchServices
directory inside your app's bundle.Label
as the key and the value must be the filename of the helper tool.SMAuthorizedClients
as its key and its value must be an array of strings. Each string must be a code signing requirement. Your app must satisify at least one of these requirements.CFBundleVersion
as its key and its value must be a string matching the format described inCFBundleVersion
's documentation.SMJobBless
will not overwrite an existing installation of a helper tool with one that has an equal or lower value for itsCFBundleVersion
entry.SMPrivilegedExecutables
as its key and its value must be a dictionary. Each dictionary key must be a helper tool's filename; for example "com.example.YourApp.helper". Each dictionary value must be a string representation of a code signing requirement that the helper tool satisfies.If you want to see a sample project that is configured to satisfy these requirements, you can take a look at SwiftAuthorizationSample.