Did you know that you can have Mac OS X run a script whenever you log in to your computer? You can if you create a “login hook.” A login hook tells Mac OS X to execute a certain script when a user logs in. Unlike Startup Items that open when a user logs in, a login hook is a script that executes as root. This advanced article shows you how to set up a login hook.
With a login hook:
* The script specified as a login hook must be executable.
* The login hook will be run as root.
* In the login hook script, the variable $1 returns the short name of the user who is logging in.
* Other login actions wait until the hook has completely executed.
How to set up a login hook
Mac OS X 10.3, 10.4, or later
Note that with Mac OS X 10.3.x and 10.4.2 or later, you can use the alternative method at the bottom of this document instead, if you wish. For Mac OS X 10.4 and 10.4.1, you should always use the following steps:
1. Open Terminal (Applications/Utilities).
2. In the Terminal window, type:
sudo defaults write com.apple.loginwindow LoginHook /path/to/script
(where /path/to/script is the full path to the script that you want to execute when a user logs in—it doesn’t have to be in the user’s Home directory).
This modifies the /var/root/Library/Preferences/com.apple.loginwindow file.
3. Type your password at the prompt, then press Return.
6 responses to “Creating a login hook…”
How does one bypass a login hook that is misbehaving (i.e. never exits)? Is there a login key sequence you can hold down to skip them?
I would think that booting into single user mode would help with this. When you reboot the mac as soon as you hear the chime, hold down the “s” key and your mac should boot into single user mode. Then you should be able to use the command from the tip without the path (ie:blank) to reset the value. Once done….reboot.
thats useless…delete this post
What’s useless specifically and why? If you can not be specific please do not comment anymore.
Many,I imagine he is saying it's useless because the filesystem is not mounted by default in SU mode, so most likely the loginwindow file won't get touched. you could mount / first though and then do it.
Thanks for the clearification Gregg. Gotta love comments that just say "This sucks"……anyways……moving on…..
Thanks again for the extra info/clearification :-)