Address Book ignores my phone sort and retains it's own order??!?

I’ve got my script working now. It takes two phone numbers of the chosen Contact and swaps their location.

Now, however, another problem has come to light. Address Book seems to be disregarding the new order! When I export the contact as a V-card and look at the data it’s re-ordered, but Address Book takes over and does it’s own thing to it. Even importing the V-card does not get the phone numbers to reorder.

Believe it or not, I’ve narrowed the problem down to the labels. If the labels are in lower case Address Book accepts the new order just fine. But if I put the labels in caps Address Book ignores the new order. It seems to retain the original order and keeps like labels together. I’ve been testing different label combinations and it seems AB (Address BooK) reorders the data when the labels are all caps and under three letters in length. Can anyone confirm this or direct me to some info about this strangeness?

Labels I’m using:

So if I’ve got a label set of: B,DD,Bfx,H,B,C,DD
Once ABook saves the order automatically becomes: B,B,DD,DD,C,H,Bfx
And it cannot be changed (regardless of the actual data ordered in the V-card!).
Help? Ideas?


tell application "Address Book"
	set PersID to selection
	set PersName to (item 1 of PersID)
	set foneL to label of phone of PersName
	set foneV to value of phone of PersName
	tell application "Finder"
		choose from list foneV with title ¬
			"Swapping Phone List Order" with prompt "Swap which phone numbers?" with multiple selections allowed
		set thePhoneNum to the result
	end tell
	tell application "Finder"
		set newphoneorder to {}
		set newphoneorder to newphoneorder & (item 2 of thePhoneNum)
		set newphoneorder to newphoneorder & (item 1 of thePhoneNum)
	end tell
	set phoneID to {}
	repeat with m from 1 to count of newphoneorder
		repeat with l from 1 to count of foneV
			if item l of foneV = item m of newphoneorder then set phoneID to phoneID & l
		end repeat
	end repeat
	set firstfoneL to (item (item 1 of phoneID) of foneL)
	set secondfoneL to (item (item 2 of phoneID) of foneL)
	set firstfoneV to (item (item 1 of phoneID) of foneV)
	set secondfoneV to (item (item 2 of phoneID) of foneV)
	set (item (item 1 of phoneID) of foneL) to secondfoneL
	set (item (item 2 of phoneID) of foneL) to firstfoneL
	set (item (item 1 of phoneID) of foneV) to secondfoneV
	set (item (item 2 of phoneID) of foneV) to firstfoneV
	delete (phones of PersName)
	save addressbook
	--this part to help me in debugging
	log "foneL: " & foneL as text
	log "foneV: " & foneV as text
	delay 5
	--end help
	repeat with P from 1 to count of items in foneL
		tell PersName to make new phone at end of phones with properties {label:(item P of foneL), value:(item P of foneV)} --
	end repeat
	save addressbook
end tell


Here’s the skinny as I see it:

Address Book gives special sort priority to the phone labels that are being used by the Template prefs pane (ie, those labels are always first and kept together).