Running a script in iChat (instead of sound)

Is it possible to run a script instead of playing a sound in iChat? I want a script to run whenever a new buddy logs on, kinda like making a rule in mail. Is there a way to do this? (easily)

Since you highlight the ‘easily’ part, the answer is no.

To do this easily, iChat would have to add a ‘run AppleScript’ option to the message preferences along with the existing ‘play sound’, ‘bounce icon’, etc.

There is a way of doing it, although it’s not that easy - you’d have to periodically check the status of every buddy and compare it to their status the last time you checked. Any changes would indicate a sign on or sign off. Not for the faint-hearted.

could you demonstrate a script of how this would work?

This code should give you an idea.

When it starts it grabs the list of current users. it then checks once per minute (based on the return 60 in the idle handler) to refresh the list and compare it to the previous set. Any changes indicate someone new joined or an existing user left.
You can add additional logic to this code to detect if the change is a new user or an old one.

global onlineAccounts

on run
	-- get the list of people online when we start
	set onlineAccounts to my getOnlineUsers()
end run

on idle
	-- see who's online now
	set onlineNow to my getOnlineUsers()
	-- compare the now list to the previous list
	if onlineNow is not equal to onlineAccounts then
		--if they don't match, do something special
		-- you can extend this to check the list to see
		-- if the change is a new user or an old one leaving
		display dialog "The list of online users has changed"
		-- record the current set of users for the next check
		set onlineAccounts to onlineNow
	end if
	-- check again in 60 seconds
	return 60
end idle

on getOnlineUsers()
	tell application "iChat"
		set activeUsers to name of every account whose status is available
	end tell
	return activeUsers
end getOnlineUsers

Note, though, that limitations in this process mean that you won’t notice multiple changes within the idle period - for example, if you check at 12:00:00 and someone comes online at 12:00:10, then departs at 12:00:40, the next check at 12:01:00 will not see them and would never know they were there.

did you test this? its not working for me.