I am having a programming decision problem and hope, that you can show me a solution or tell me, if my plan on how to solve the problem would be okay or not.
I am managing some macs and want to run a script every time a user logs in. The script (which I haven't written yet) needs to make some changes (or not). The changes need administrator privileges but the script also needs information from the currently logged in (or logging in) user.
Normaly, this would be a job for a LaunchAgent / Deamon, but here comes the problem: Scripts in /LaunchDeamons run as system administrator but start together with the system. They are not aware of users loging in or out and they may not show a GUI. ~/LaunchAgents run as the logged in user and get started when the user logs in. Also they may show a GUI. However they do not run as system administrator.
So this is my problem: running a script as root, but starting it whenever a user logs in and present a GUI to him: My solution would be to write two scripts:
Script 1 runs as system administrator and lies in /LaunchDeamons. This would have a Socket open for incomming connections (AKA "Server Socket").
Script 2 runs as the user beeing logged in and lies in ~/LaunchAgents. It presents a GUI to the user and sends the information to script 1 via a socket connection.
It doesn't seem to me as this would be the most reliable / straight forward solution, but I can't think of anything else. I also tried to find out how other programs solve this problem (munki for example, which presents a GUI to the user but installs programs as system administrator) but couldn't figure out how they did it.
I'd be happy for some comments on this! Regards, Christian
PS: I plan to use python.