How to running application under root privilege?

2019-08-29 08:40发布

问题:

Please tell me a way grant for my application to modify /Library/Fonts folder as add new and remove font file. Thanks in advance.

回答1:

  • You can split your application into two parts: service(daemon) and UI and install them via installer in the way so your service will have root privileges
  • You can run some command from your app using AuthorizationExecuteWithPrivileges() but it is deprecated. Still it works
  • You can run some command via NSAppleScript using "do shell script \"some script\" with administrator privileges". But it more like a hack and apple documentation says that NSAppleScript class must be used only from the main thread of an application. But it works too, and personally I don't have any troubles with that.
  • You can create helper tool and use ServiceManagement.framework and SMJobBless()

You can find some additional info here and here