I'm toying around with building a custom render farm manager, and I want to automatically add OS X machines to the render farm when they are not in use.

Is there a way to trigger a script to run once any user has logged out then stop when any user has logged in?

link|improve this question
feedback

1 Answer

up vote 4 down vote accepted

There are several ways to run scripts at login/logout in OS X, some are more recent and only apply to 10.5 and above, some are rather deprecated, but the fastest one would be to add a Login Hook.

Open up the Terminal, and enter

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

There's also the Logout Hook counterpart:

sudo defaults write com.apple.loginwindow LogoutHook /path/to/logout/script

I've tested this on OS X 10.6, and it should work. Keep in mind that the script runs as root and there is only one hook for login and logout respectively.

To undo all that, enter

sudo defaults delete com.apple.loginwindow LoginHook
sudo defaults delete com.apple.loginwindow LogoutHook

Note that this method is not recommended for deployment or anything, but if you're only using it like your question stated, that should be no problem.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.