Run script on login *as root* on Catalina
In this question, a response details that com.apple.loginwindow
login hooks can be used to run script as root on user login.
I have followed the instructions by using
sudo defaults write com.apple.loginwindow LoginHook /Users/Shared/Test.sh
except nothing is executed on login. My script makes use of a small background process and nothing else and works by typing it into my terminal so I am lead to believe that it simply isn't possible anymore.
If this method (as it is already deprecated) no longer works, are there any method that currently work for running login scripts as root?
I recommend using crontab
.
Open the root user crontab (this will create a new crontab
file if you don't have it):
sudo crontab -e
Add you command, with the time you want it to run in front (if you want to do it at a specific time, you can use this handy tool):
@reboot /Users/Shared/Test.sh
Exit and save the file.
That's it! Your command should now run whenever your computer starts up. While this isn't technically the same as on login, it should be enough for almost all intents and purposes.