Reputation: 25
I'm trying to run the setpriority
command from my macOS app (objective-c). It never works and I'm assuming it is because the app is not being run as the root user.
sudo
chmod
on the appAccessibility
list under Security and Privacy
Xcode version 9.2 (9C40b)
I would appreciate any help, thanks!
Upvotes: 1
Views: 3887
Reputation: 17040
It's not recommended to run GUI apps on macOS as root. Instead, you should factor out the part of your application which needs root access into a separate helper tool, launch that tool as root using the SMJobBless()
function, and then communicate with the tool using XPC.
Apple provides the EvenBetterAuthorizationSample example code to give a pretty good basic framework to work from.
EDIT: I decided to make my own authorization sample project a while ago that should be a little easier to use than the venerable EvenBetterAuthorizationSample
. You can check it out at CSAuthSample.
Upvotes: 1
Reputation: 12566
You want to run as root
, or you want to run with sudo
? There's a difference. Running as root is definitely not recommended, you will get strange behaviour from the system.
You wrote:
I've tried opening the app with sudo
That should work. How have you tried? You need to call the binary within the .app bundle. Running open
against the bundle won't work.
e.g.
sudo ./Xcode.app/Contents/MacOS/Xcode
Upvotes: 2