Help! address book shows (null) when I add to emal

For some reason when I add certain contacts to emails they show up with a (null) next to them and won't send. here is an example with a jon doe email
(null) <johndoe@mac.com>
any ideas how to fix this. I just noticed that it only happens when I drag contacts from the address book app not when I add them from the address book window in the email.

MacBook Pro 15", Mac OS X (10.4.8)

Posted on Nov 24, 2009 8:05 AM

Reply
17 replies

Nov 24, 2009 6:49 PM in response to Bucknut

The string "(null)" is the textual representation of an Objective-C nil value. (For example, executing the following code would print "(null)" to the system log:


NSLog(@"%@", [nil description]);


If Mail is filling in the To: field with "(null) <johndoe@mac.com>", only when you drag it from Address Book, there may be a —.

LOL, I just tried it myself and get the same behavior.

Okay, this only occurs when you have no name set for the contact in Address Book. There are a couple of reasons why this behavior wouldn't occur when you add the contact from within Mail itself. Actually, after further testing, I've narrowed it down even further. This behavior only occurs when you drag and drop an email that has no name set for it. The reason for this is that it looks like the text fields in Mail's new message window are custom subclasses, meaning they are handling all of the drag-and-drop code themselves. That code is separate from the code that handles choosing a contact from the list by double-clicking on it. Whoever wrote that code was a little lazy. They should be testing for values that are nil and excluding those values from the display string that is being constructed. (Assuming all values are non-nil can be deadly in certain situations; here it's merely inelegant.)

Well, I've found a solution/workaround, though it's not very elegant. Go into Address Book and edit the contact to give them a blank name of one space for both their first and last names. Click the Edit button again to save your changes. Click Edit again and delete the space you added to the first and last names so that the names are now empty strings. Click the Edit button to save your changes. Open a new "New Message" window (doesn't work for existing ones that have the (null) displaying in the field), and drag and drop the contact from Address Book to Mail. You will now only get the email address in the "token" that's added. What you did in Address Book is first set the values for first and last names to something that was non-nil. Then you deleted it so it was only an empty string, which is different than nil. (nil means nothing at all, an empty string, even though it has 0 characters, is still a string).

There should be an easy way to automate this if you have a lot of contacts without proper names. In AppleScript, you'd check to see if the first and last name properties are "missing value" and if they are, set it to "".

I'll file a radar about this.

Anyway, excuse the overly-technical reply (I've been programming for too long today). Hope this helps....

Nov 24, 2009 7:17 PM in response to Bucknut

Filed as Bug ID #7423099: Mail: drag-and-drop contact w/ nil names adds (null) to displayed email address. [Bug ID #7423099: Mail: drag-and-drop contact w/ nil names adds (null) to displayed email address|rdar://problem/7423099]

(Note that that URL is meant for, and will only work for, the people inside Apple; it's the way they refer to specific bugs).

EDIT: bah! I give up, forum software doesn't like funky URL types it appears.

Message was edited by: MarkDouma®

Nov 25, 2009 2:39 AM in response to V.K.

Weird, I just tried my workaround now and it doesn't work either. Address Book is also not behaving the same way it did before when I tried that trick. I thought I remember that when I changed the name to one space for each of the names, the name displayed in the Name column of Address Book changed to reflect that. Now it continues to show my "blah@fake.com" email address the entire time.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help! address book shows (null) when I add to emal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.