Set Address Book Nicknames

I have a bad habit of typing faster than Mail can autocomplete the “To” field when I’m composing a new email, then tabbing to the next field. This leaves my email addressed to “walt” or “pete” without a valid email address. Then when I try to send the email, it won’t send and brings up a dialog box that the server won’t accept the email.

I found the solution was to set nicknames in Address Book. My copy didn’t have the nickname field enabled, so in the Preferences I chose “Templates” and added “nickname” to my address card template.

Then this script copies the first name of every person into the nickname field:

set myCount to 0

tell application "Address Book"
	repeat with myperson in (every person whose first name is greater than " ")
		tell myperson
			set theName to (get first name)
			if length of theName is not 0 then set nickname to theName
		end tell
		set myCount to myCount + 1
	end repeat
end tell

display dialog "Set nicknames for " & myCount & " people."

Now when I type a partial name and quickly tab to the CC field, Mail recognizes the short name of the person and put’s the email address for that nickname in the “to” field.