/PrivilegedTaskRunner

Swift 4 example code for creating privileged helpers in macOS

Primary LanguageSwift

Privileged Helper Example with Swift 4

My take on privileged helper, thanks to Erik's privileged helper tool example

Update: Erik's new privileged helper example is quite perfect, so I won't probably update this anymore.

Project and Target

  • Create a project (for example, a normal Cocoa project, like PrivilegedTaskRunner in this example)
  • Create a new command line target (PrivilegedTaskRunnerHelper)

Target Settings

  • PrivilegedTaskRunner -> Copy helper (Build Phases)
  • PrivilegedTaskRunner -> Compile sources (Build Phases)

Make sure that target name for helper tool is with full namespace (for example: com.suolapeikko.examples.PrivilegedRunnerHelper)

Helper Linker Settings

  • Helper -> Build Settings -> Linking -> Other Linker Flags
	-sectcreate
	__TEXT
	__info_plist
	"$(SRCROOT)/PrivilegedTaskRunnerHelper/PrivilegedTaskRunnerHelper-Info.plist"
	-sectcreate
	__TEXT
	__launchd_plist
	"$(SRCROOT)/PrivilegedTaskRunnerHelper/PrivilegedTaskRunnerHelper-Launchd.plist"

Plist Files

  • See PrivilegedTaskRunnerHelper-Info.plist and PrivilegedTaskRunnerHelper-Launchd.plist
  • Anchor line with Certificate info needs to be created by Apple's tool called SMJobBlessUtil.py

SMJobBless creates lines to Info.plist and Helper-Info.plist:

./SMJobBlessUtil.py setreq PrivilegedTaskRunner.app PrivilegedTaskRunner/Info.plist PrivilegedTaskRunner/PrivilegedTaskRunnerHelper-Info.plist

SMJobBless contains requirements checker:

./SMJobBlessUtil.py check PrivilegedTaskRunner.app