Start/Assign macOS app with root privileges

xcode root sudo nsapplescript

72 观看


2597 作者的声誉

I have written a macOS Cocoa app using XCode 9.2.

The purpose of the app is as a wrapper to a set of shell commands so that users can run commands easily as required. The shell script allow the users to control a particular device driver for which the software is written by another party.

I have managed to get the app to invoke the shell command as root.

But there are some sub-commands that fail. The actual commands run are, and I think it is the 2nd "stop -a" that fails:

do shell script \"
cd '/Library/Application Support/ABC' ;
 python '/Library/Application Support/ABC/' stop -d;
 python  '/Library/Application Support/ABC/' stop -a;
 python '/Library/Application Support/ABC/' stop -g;
 python '/Library/Application Support/ABC/' stop -t;\"
 with administrator privileges

When I run the same commands in Terminal they work, either as discrete commands or in a shell script.

As a last resort I ran the app from the command line using

sudo ~/Library/Developer/Xcode/DerivedData/appname/Build/Products/Debug/

And this works perfectly.

So, it seems that when I run using the NSAppleScript framework, which correctly prompts me for the root password, there is still something amiss which causes the command failure. But when the whole app runs under sudo everything works.

So the solution appears to be to set the app to require Root privs. Is there a setting that can be set for the built project that would automatically set this such that the root password is requested on startup?

作者: TenG 的来源 发布者: 2017 年 12 月 27 日

回应 (1)


2597 作者的声誉

Seems to be working in that I do not get the error, but would still like some pointers on how to set an app to run as admin.

作者: TenG 发布者: 28.12.2017 12:20