In OS X you can create a pre-login launchd agent. For example save this property list as /Library/LaunchAgents/some.label.plist
:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>some.label</string> <key>LimitLoadToSessionType</key> <array> <string>LoginWindow</string> <string>Aqua</string> </array> <key>ProgramArguments</key> <array> <string>say</string> <string>a</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
Make sure the plist is owned by root. If it is not, it can be loaded if you run launchd load
as the user but it is not loaded by launchd automatically.
Then if you restart, the say command should be run once when the login window is shown and again after a user logs in graphically.
If you don't want the program to be run again when a user logs in graphically, remove <string>Aqua</string>
.
If automatic login is enabled and LimitLoadToSessionType
is set to just LoginWindow
, the program is not run at all.
See the Daemons and Agents tech note or man launchd.plist
for more information.