Counting Online Buddies

I am trying to count all the buddies that are online in iChat. Can someone please tell me what is wrong with:

tell application "iChat"
	set onlinecount to 0
	set nameList to (name of account of service 1)
	repeat with currentNumber from 2 to length of nameList
		if status of account currentNumber is available then
			onlinecount = onlinecount + 1
		end if
	end repeat
	return onlinecount
end tell

Try this:

set q to 0
set w to 0
set e to 0
set r to 0

tell application "iChat"
	set a to count every account
	set a to a as integer
	set a to a - 1
	repeat with x from 1 to a
		set b to status of account x as text
		if b = "available" or b = "«constant ****aval»" then
			set q to q + 1
		else if b = "away" or b = "«constant ****away»" then
			set w to w + 1
		else if b = "idle" or b = "«constant ****idle»" then
			set e to e + 1
		else if b = "offline" or b = "«constant ****offl»" then
			set r to r + 1
		end if
	end repeat
	
	display dialog "You have got " & a & " Buddies." & return & return & ¬
		"Available: " & q & return & ¬
		"Idle:         " & e & return & ¬
		"Away:      " & w & return & ¬
		"Offline:    " & r ¬
		as text buttons "OK" default button 1 with icon 1
end tell

You could just ask for a list and count the number of items in it, rather than looping through them one at a time:

tell application "iChat" to display dialog (count of (name of every account whose status is available)) as text

Er, how about this?

set onlinecount to onlinecount + 1

dkmarsh: For the AIM and Bonjour accounts, that list will include yourself. Something like this should handle that:

tell application "iChat" to display dialog (count (name of every account whose status is available and name is not "Your Name"))

By the way, to General:

The problem in your script is the line onlinecount = onlinecount + 1, which you probably intended to write as set onlinecount to onlinecount + 1 (as it is, I’m guessing that AS sees the line as the statement 0 = 1, and evaluates it as false, which is why it doesn’t throw an error).

Yeah, what Bruce said. :rolleyes:

I believe that is correct.

Thanks! It’s Faster than my! :smiley: