I'm trying to run a command at login/logout which requires
sudo. I've read about
LaunchAgent but as I understand it,
LaunchDaemon will run the command at startup with root permissions, and
LaunchAgent will run it at login but with the current user permissions, which won't always be an administrator.
Alternatively, is there a way to run my command without the need of
sudo? I'm trying to wipe all files in the home directories (Desktop, Documents etc.) on user login/logout so am currently using
sudo rm -rf /users/randomuser/Desktop/* etc. Similar to how a guest account works, but without the account being guest and with a little more control. I'm pretty new to this kind of thing so please explain like I'm 5. More than happy to try out another solution if required. Thanks!
EDIT - Thanks for the help so far. Here's a bit more detail about the use case:
I have a mac that will be used by myself (admin) and a few other people (second account). I don't want data to persist between logins on this second account, similar to how the Guest Account works. The problem with the guest account is, it resets applications placed in the dock between logins as well as resetting the desktop wallpaper (which I would like to keep the same throughout logins). My solution was to set up a standard account, lock the dock using
defaults write com.apple.Dock size-immutable -bool yes and set the wallpaper manually. As for the data, I would like all files that have been downloaded or transferred by the user to be wiped when the user logs out (or equally, when the next user logs in). Alternatively, If there is a way for the Guest Account to not reset the dock and wallpaper on logout, this would also work. Thanks again!