I'm getting ready to deploy an app on OS X. This is the first time I've written an application on this platform which requires root permissions to run properly, so I need that functionality integrated for every startup attempt.
The application itself is written in Python 2.7, and then compiled to binary using PyInstaller. So far, I've tried:
Running PyInstaller using
sudo pyinstaller -w --icon=/path/to/icon /path/to/script.py
Invoking the PyInstaller command using
sudo su
I don't know what else to try at this point. Is it something that could be achieved using symlinks?
Running the installer as root will have no effect when you later start the application itself as a normal user.
Try
sudo python /path/to/script.py
instead.If that works, then put this into a shell script and run that to start the app as root from now on (and the people who know MacOS can probably tell you how you can create a nice icon for the script).
WARNING Doing this makes your system vulnerable to attacks. If you do this on your own Mac, that's fine. If you're developing a product that you're selling to other people, then you need to revisit your design since it's severely broken.
Apple recommend that no GUI applications run as root, as the libraries that are included in such applications increase the attack vector for malware.
Instead, it is recommended to refactor your code into two parts, the Gui and a separate helper app, which is given root privileges.
There's an example application here.