help with iChat AV script for newbie

Okay, I am very new to applescript. I read a few pages of apple’s docs then got bored and went right to scripting.

Basically I want to make a script that returns a list of all online, offline or idle users. Here is what I have (ignore the poor variable naming).

on run
tell application “iChat”
activate
log in
set numberofitems to account count
repeat with n from 1 to numberofitems by 1
if {account n, status is available} then
set bob to {account n, name}
set bob to babafett as item
end if
end repeat
end tell
end run

It tells me that no result was returned from that bit in the brackets (between if and then). I don’t get it because this looks fine to me. Help?

If you look at the iChat dictionary, you’ll see that status is a property of account. Try this:

if status of account n is available then

instead of

if {account n, status is available} then

A better way would be to skip the if statement altogether (you wouldn’t need to get the count either).

repeat with every account whose status is available
   --whatever you want to do with each available account
   --remember to use an array if you want to make a list
end repeat