Auto Run A Script When Login On Mac Os X

Setting Up:

$ sudo defaults write com.apple.loginwindow LoginHook "/Users/$(logname)/Bin/loginhook.sh"

注:一定要加sudo,否则不管用。

$ sudo defaults read com.apple.loginwindow LoginHook
/Users/mitnk/Bin/loginhook.sh

$ cat ~/Bin/loginhook.sh
#!/bin/sh
logger -i "Login Hook Test at `date`"

$ open -a Console /private/var/log/system.log

也可以设置Logout Hook:

$ sudo defaults write com.apple.loginwindow LogoutHook "/Users/$(logname)/Bin/logouthook.sh"

参考:雷哥 & Apple