Spaces in phone numbers in address book

Address book formats numbers for you in custom ways this is good. but sometimes these numbers might be saved with spaces in them, i noticed this when another application was using the address book and displayed a few numbers with unexpected spaces.

this little script will do a check for you and if you want to it can fix them as well:

the check will not modify your address book at all and will give you a count and names that would be affected if you were to do a fix.

AS A PRECAUTION JUST TO BE SAFE: If you are going to do a FIX do backup of your address book database first

set nameList to " names have a space in one of their phone numbers:\n"
display dialog "" buttons {"Check", "Fix"} default button 1
if the button returned of the result is "Fix" then
	set Fix to 1
else
	set Fix to 0
end if

tell application "Address Book"
	set counter to 0
	
	repeat with thisPerson in every person
		set theirName to ""
		repeat with theirPhone in every phone of thisPerson
			if the value of theirPhone contains " " then
				set counter to counter + 1
				set theirName to first name of thisPerson & "\n"
				if Fix is equal to 1 then
				   try
					set theNumber to value of theirPhone
					set value of theirPhone to do shell script "echo " & theNumber & "| tr -d ' ' "
				   end try
				end if
			end if
		end repeat
		set nameList to nameList & theirName
	end repeat
	
end tell
display dialog (counter as string) & nameList