What's the best way to run a script with root privileges whenever any user logs in? It should run in the background without prompting the user for a password.

  • Logs in through the Finder GUI or opens a terminal prompt?
    – beroe
    Commented Sep 2, 2014 at 19:20
  • Through the GUI Commented Sep 3, 2014 at 20:01

2 Answers 2


Use a LoginHook.

sudo defaults write com.apple.loginwindow LoginHook /path/to/script

See here for more detail.


I still haven't found a way to do exactly this, but since the script I need to run is just a chmod command, it's sufficient to run it via a launchdaemon every 10 seconds instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .