QuitMsg installs a handler that gets executed when the user tries to quit by clicking the close button, pressing Alt-F4, or using the system menu. You need to use the exitLock to true to stop Director from quitting, but naturally you can also use a Quit command in your quitMsg handler after doing some cleanup task. Here is an example of the scripts.