newbie needs help when closing a window

i’ve been sifting through reference manuals trying to find an example of this. basically, i’m trying to perform an event when i close a window of a particular application. specifically, i’m trying to have aim dump the history when i close an im window. any ideas?

i know it’s something like:

using terms from application "AOL Instant Messenger (SM)"
on close window ("Instant Message with " & inScreenName)
set theMessage to (history of im session 1)
display dialog theMessage buttons {"OK"} default button "OK"
end using terms from

Well, it seems you want this script to run WHEN you close said window. But scripts aren’t generally geared to wait for an event before executing.

For AppleScript to fit your needs, you’d have to run the script first, then have an idle handler, (I think) to keep checking for the existence of said window. When the the check returned false, the script would then do your required commands.

Can someone shed further light?