425nesp
425nesp

Reputation: 7583

Application, Helper Tool Communication

I'm working on a OS X desktop application. I want to bundle a helper tool with it. I was thinking of using SMJobSubmit to start a helper program with elevated privileges. (The tool basically does a sudo call.)

How could I send the console output from the tool back to my main application?

I know with NSTask I could use NSPipe to redirect console output. But, since I don't think I can use NSTask with elevated privileges, I'm using SMJobSubmit instead.

(Yes, I've taken care of the authorization part.)

Upvotes: 0

Views: 455

Answers (1)

Vinod Madigeri
Vinod Madigeri

Reputation: 177

I think, as far as I know, you should use XPC connection to communicate with your helper program. Instead of using SMJobSubmit(Since it is deprecated anyway) use SMJobBless to install your helper tool as a LaunchD job which runs in elevated privileges. Use XPC connection from your Mac OS X app to communicate with it to invoke the function call that executes your logic, capture the output and reply back to the main app. If you are willing to go ahead with this idea, the below sample code from Apple will guide you through.

https://developer.apple.com/library/mac/samplecode/EvenBetterAuthorizationSample/Listings/Read_Me_About_EvenBetterAuthorizationSample_txt.html

Upvotes: 1

Related Questions