My app needs a HelperTool which runs as root.
I did in Xcode Version 14.3.1 (14E300c), macOS 13.4.1 (22F82):
• Create new Project: macOS App: TestSM • Add new target: XPC Service: HelperSM • make new Property List: smProp.plist with: Label de.mdenkmann.HelperSM BundleProgram /Contents/XPCServices/HelperSM.xpc/Contents/MacOS/HelperSM • add Copy File Build Phase in TestSM for smProp.plist with: Destination: Wrapper Subpath: Contents/Library/LaunchDaemons
smAppService = SMAppService.daemon(plistName: "smProp.plist")
smAppService.register()
now: smAppService.status = "enabled"
When I do: let connectionToService = NSXPCConnection(serviceName: helperSMBundleIdentifier) I can communicate with HelperSM, but it does NOT run as root. Bad.
When I do: let connectionToService = NSXPCConnection(machServiceName: "de.mdenkmann.HelperSM", options: [. privileged]) I get NSXPCConnectionInvalid when I communicate with the HelperSM. Even worse.
How to get my root Helper?
When I look at: System Settings → General → Login Items → Allow in the Background I see: TestSM.app 3 items; 3 items affect all users.
What are these 3 items? Why Background? I want my HelperSM get started as root when called from TestSM, then run it as long as the system sees fit, then stop. It should not be called from other apps. It has no need to run in the background once TestSM stops.