May 1st, 2008 by qiushihe | Posted in Tips | 2 Comments »
I recently setup a Jabber account on my server and started to use the MSN transport on it to access my MSN account. Thus I am now able to use the fantastic iChat as my only IM client (since iChat itself can handle .Mac, and Google Talk). However there was one problem: all my MSN contacts shows up through Jabber as
some_name%some_server@msn
and in order for those MSN contact to be displayed as the person’s name, my Address Book entry for those people must have “some_name%some_server@msn” as the person’s Jabber Handle. Since I am a reasonably lazy person and wasn’t exactly prepared to enter all those entries by hand, I wrote the following Applescript to automate the process.
This script will go through all iChat service, look for contact address that ends in “@msn”. Then for all those contacts, search the Address Book entries that contain the corresponding MSN address (some_name@some_server). Then check to see if that person already have a Jabber entry, if not add it.
tell application “iChat”
set all_jabber_accounts to {}
set unique_pairs to {}
set added_jabber to “”
repeat with this_service in services
set all_buddies to buddies of this_service
repeat with this_buddy in all_buddies
if name of this_buddy ends with “@msn” then
set all_jabber_accounts_ref to (a reference to all_jabber_accounts)
set buddy_jabber to name of this_buddy
if all_jabber_accounts_ref does not contain buddy_jabber then
copy buddy_jabber to the end of all_jabber_accounts_ref
set AppleScript’s text item delimiters to “@”
set parts to text items of buddy_jabber
set AppleScript’s text item delimiters to “”
set msn_address to item 1 of parts
set AppleScript’s text item delimiters to “%”
set parts to text items of msn_address
set AppleScript’s text item delimiters to “”
set msn_name to item 1 of parts
set msn_server to item 2 of parts
set buddy_msn to msn_name & “@” & msn_server
set this_pair to {buddy_jabber, buddy_msn}
set unique_pairs_ref to (a reference to unique_pairs)
copy this_pair to the end of unique_pairs_ref
end if
end if
end repeat
end repeat
repeat with pair_i from 1 to the count of items in unique_pairs
set this_pair to item [pair_i] of unique_pairs
set buddy_jabber to item 1 of this_pair
set buddy_msn to item 2 of this_pair
tell application “Address Book”
repeat with this_person in every person
set is_this_person to false
if (count of MSN handles of this_person) is greater than 0 then
repeat with i from 1 to the count of MSN handle in this_person
set this_msn_handle to value of MSN handle [i] of this_person
if this_msn_handle is equal to buddy_msn then
set is_this_person to true
end if
end repeat
end if
if is_this_person then
set needs_to_add to true
if (count of Jabber handles of this_person) is greater than 0 then
repeat with j from 1 to the count of Jabber handle in this_person
set this_jabber_handle to value of Jabber handle [j] of this_person
if this_jabber_handle is equal to buddy_jabber then
set needs_to_add to false
end if
end repeat
end if
if needs_to_add then
set added_jabber to added_jabber & “* “ & (name of this_person) & ” “
make new Jabber handle at end of Jabber handles of this_person with
properties {label:”Jabber MSN”, value:buddy_jabber}
end if
end if
end repeat
end tell
end repeat
if added_jabber is not equal to “” then
display dialog “Jabber MSN Account added to: “ & added_jabber
else
display dialog “No Jabber MSN Account added”
end if
end tell