Problem getting iChat to quit fully

I’m new at working with Applescript, and I’m not a programmer, so please bear with me, as I’m sure this has a simple solution that is just eluding me. I need to have a little script to quit iChat even though it has one or more chat windows open. The problem is that quitting with a chat open brings up a window saying that there are active chats, asking whether I am sure I want to quit (“No”, “Yes”). The “Yes” button pulses blue as the default. So I need to get past that window.

If I’ve manually quit iChat, at that point running the script:

 tell application "System Events"
	tell process "iChat"
		click button "Yes" of window 1
	end tell
end tell

works fine; iChat quits fully as intended.

But if I get iChat to quit by first scripting it to do so:

 
quit application "iChat"
tell application "System Events"
	tell process "iChat"
		click button "Yes" of window 1
	end tell
end tell

it doesn’t work. The script simply stops dead after sending the command for iChat to quit. Adding an “activate iChat” line after the “quit” line doesn’t help.

What am I missing?

Instead of doing it this way, I’d be fine if there was a way to script iChat to first close all active chats in one fell swoop, and then quit. But I can’t figure out how to do that. Like I said, I’m really new at this…

Any help would be greatly appreciated.

If you want a down and dirty way to quit iChat, this should work…

try
	do shell script "killall iChat"
end try

Tom

Thanks, Tom. I see how that might take care of it.

However, I just figured out how to solve the problem, but in an unexpected way. Turns out that the only reason I was getting that confirmation window on quitting was that I had that feature turned on in Chax, the 3rd-party input manager that offers some iChat enhancements. Turning that off in Chax (or removing Chax entirely) makes this whole problem go away, as now iChat quits without asking for confirmation, even if chats are active.

I’d still be curious as to why the original script choked, but it’s not critical any more.

Mark

Oh no, the brutal way is only for emergency, iChat is very well scriptable


tell application "iChat"
	close (windows whose name contains "Chat")
	quit
end tell