Delete an iChat's contact's IM handle

Does anyone know a way to delete one of a contact’s IM handles? I tried the regular obtuse way of deleting an item from a list by constructing a new list without the item to delete, but when I try to set the contact’s handle list to the new clean list, it barfs:


repeat with ahandle in AIM handles of thisContact
					if value of ahandle contains "gmail.com" then
						set cleanList to {}
						set theList to (handles of thisContact)
						repeat with i from 1 to count of theList
							if {theList's item i} is not ahandle then set cleanList's end to theList's item i
						end repeat
						set handles of thisContact to cleanList
					end if
				end repeat

Any ideas?

Hi,

in iChat’s dictionary I can find only a handle property of an account,
which is read only and it’s not a list

Oh, sorry, this is in a ‘Tell app “Address Book”’ block, not iChat
iChat has an AIM handles list element and all my contacts’ gmail jabber handles got somehow switched to AIM handles, and I’m trying to switch them all back automatically.

hm, I’m a litte confused about what you’re exactly want to do.
Anyway, this construction parses every AIM handle of every contact,
the part commented out I don’t really understand :wink:

tell application "Address Book"
	repeat with thisContact in (get people whose AIM handles is not {})
		set theHandles to (get AIM handles of thisContact)
		repeat with ahandle in theHandles
			if value of ahandle contains "gmail.com" then
				-- set cleanList to {}
				-- set theList to theHandles
				-- repeat with i from 1 to count of theList
				-- 	if {theList's item i} is not ahandle then set cleanList's end to theList's item i
				-- end repeat
				-- set handles of thisContact to cleanList
			end if
		end repeat
	end repeat
end tell

I am trying to change any IM handles that contain “gmail.com” to Jabber Handles, as these were incorrectly labeled as AIM handles in my Address book for some reason. But since I can’t figure out a way to coerce an AIM handle item to a Jabber handle item, I was just trying to delete the “gmail.com” handle from the AIM Handle list for a contact.

But since deleting an item from the middle of a list is a pain in Applescript I had that convoluted code that you commented out.

Thanks Jacque! Works like a charm. I didn’t know you could now use delete to remove items from a list. Good to know.

Strangely, this doesn’t work when there are multiple Aim handles in a contact and you try to delete one before the end. Say you have 3 AIM handles delete the second one, then when the loop tries to access the last one (formerly the third), the pointer no longer points to it anymore.

I tried to instead do this by starting at the end and counting backwards to 1 to avoid this issue, but trying

get count AIM Handles 

fails saying count be applied to this type. Ugh!