0

How to allow macOS application to run as root with preserving the user environment? Or ideally run the app as it is launched from terminal as sudo.

I have macOS application with GUI, MyApp.app and I need to run it as root, if user opens it(double click the app icon). If I run the application from terminal like:

cd /Applications/MyApp.app/Contents/MacOS/ && sudo ./MyApp.bin

It will ask for the privileges and everything works just fine, I am running it as root with user environment. Goal of this question is, if there is some easy solution to make this launch default or approach how to run it with sudo privileges.

I tried to make 2nd app, which launches this as root, via Apple script saved as .app, like:

do shell script "sudo /Applications/MyApp.app/Contents/MacOS/MyApp.bin" with administrator privileges

Which works, the app has elevated rights, but I do not have current user context, like I cannot access system clipboard and what worse, I am not able to access current user Downloads folder. Also I am not allowed to deleted some files which I easily as user or as sudo can.

I need my app to run as root, as it do many things like copying, unzipping libraries in system folders.

0

You must log in to answer this question.

Browse other questions tagged .