3

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?

santi_
  • 191
  • 1
  • 8

1 Answers1

1

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.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Yes, I explored the XPC / JobBless and it's not trivial at all! Similarly I would have to use `SMJobBless` for say starting or stopping a system service? – santi_ Oct 24 '18 at 05:42