开发者

How to get users mail addresses on OS X Lion?

I was getting the users mail addresses from Libraray/Preferences/com.apple.mail.plist. They are not there any more in L开发者_JAVA百科ion :P Do I have to use scripting bridge? Any hints? Thanks


I would get them right out of Address Book. That should work regardless of what email app is being used.

// Find 'me' card in address book.
ABPerson* meCard = [[ABAddressBook sharedAddressBook] me];
if( meCard == nil ) {
    NSLog( @"Could not find me!" );
    return;
}

// Get my email addresses.
ABMultiValue* anEmailList = [meCard valueForProperty:kABEmailProperty];
if( anEmailList == nil ) {
    NSLog( @"I have no email!" );
    return;
}

// Output them.
for( NSUInteger index = 0; index < [anEmailList count]; index++ ) {
    NSString* aLabel = [anEmailList labelAtIndex:index];
    NSString* aValue = [anEmailList valueAtIndex:index];
    NSLog( @"%@: %@", aLabel, aValue );
}


Mail in Lion stores the equivalent in ~/Library/Mail/V2/MailData/Accounts.plist. Note however that you are assuming that the user uses the Apple Mail program, unless that's what you really need you may want to have alternative methods for getting the address. You may for instance depending on how the system has been set up use the CSIdentity APIs, such as CSIdentityGetEmailAddress().


Apple script will get the job done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜