Reputation: 271
My app should check if a service is currently running or not. In terminal the command would be
sudo launchctl list | grep some_service
I can't seem to be able to find any resources to create and use a privileged helper to run the protected command.
I have however found this rather rough solution, but is it safe?
Also, is it possible to just elevate the permissions of the app to just run as root everytime? If so how would I do it?
Upvotes: 3
Views: 865
Reputation: 285064
The Cocoa equivalent of launchctl list
is SMCopyAllJobDictionaries(_:) in the ServiceManagement framework.
It's deprecated for a while but it still works.
A privileged helper can be created with SMJobBless(::::) and an XPC service, but this is not trivial to accomplish.
Upvotes: 1