Appending country code to all contact numbers

Appending country code to all contact numbers

And so I got the LG Optimus One for a family member and transferred over his contacts easily thanks to Mac OS X Address Book’s built-in ability to synchronize with Google Contacts. The Google Android platform certainly has some excellent features not found in the iPhone ‘s iOS – but more of that in another (future) post.

The only problem was that the Optimus One could not seem to identify  a caller if his contact entry did not have the country/area code appended. As the family member’s previous phone was an old non-smartphone candy bar type, almost all his contacts did not have the country code! I was dreading the need to spend an entire afternoon doing data entry when I chanced upon an elegant solution on the Apple discussion forums.

Basically you need to launch the Applescript Editor and paste in this code

property myAreaCode : "65 "
tell application "Address Book"
	repeat with aPerson in people
		set thePhones to phones of aPerson
		if thePhones is not {} then
			set errorList to {}
			repeat with aPhoneNumber in thePhones
				set theNumber to value of aPhoneNumber
				if length of (theNumber) is less than 10 then

					try
						set value of aPhoneNumber to myAreaCode & value of aPhoneNumber
					on error
						copy name of aPerson to end of errorList
					end try
				end if
			end repeat
			if errorList is not {} then
				display dialog errorList
			end if
		end if
	end repeat
	save
end tell

Now select the contacts in whose numbers you want to change and click Run in Script Editor. This will add 65 to the front of all phone numbers of all selected people, if their current numbers are less than 10 digits long (the typical phone number in Singapore with country code is 10 digits long – you may need to change this setting).