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 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.
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 sudo rights, but I do not have current user context, like I cannot acces system clipboard and what worse, I am not able to access current user Downloads folder.
I need my app to run as root, as it do many things like copying, unzipping libraries in system folders and changing it will take a lot of time.
Therefore I am looking for some simple solution, how to achieve the app runs with root access, but preservs current user environment, like it does If I run it from showed command terminal.
I have tried to make 2nd app, which runs it via shell script, Apple script, osa scrip, tried to bundle shell script to the app, but Apple did not notarize that.
Tried to change the Apple script commands to do shell script “sudo -E /Applications/MyApp.app/Contents/MacOS/MyApp.bin” with administrator privileges or do shell script “sudo -u $USER /Applications/MyApp.app/Contents/MacOS/MyApp.bin” with administrator privileges
but nothing helped. It is ok, if there will be showed window, where is user asked for his login / password, I am ok with that.