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:
- Open Terminal (Applications/Utilities).
- 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.
- Type your password at the prompt, then press Return.
Mac OS X 10.2.x, 10.3.x, or 10.4.2 or later
- Open the /etc/ttys file: In the Finder, choose Go to Folder from the Go menu, type /etc/, then click Go.
- In the resulting window, open the ttys file in your preferred text editor (such as TextEdit).
- Look for a line that reads:
#console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" vt100 on secure window=/System/Library/CoreServices/WindowServer onoption="/usr/libexec/getty std.9600" - Edit this line so that it reads as follows (there are no breaks in this line):
#console "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow -LoginHook /path/to/script" vt100 on secure window=/System/Library/CoreServices/WindowServer onoption="/usr/libexec/getty std.9600"
(where /path/to/script is the full path to the script that you want to execute when a user logs in). - Save the file.
Be sure that the text editor you use to edit this file does not break the line above into more than one line. This method will also work in Mac OS X 10.3.