2011-10-20 111 views
2

這是我使用的代碼:無法解析由NSAppleScript方法executeAndReturnError返回的結果

NSDictionary *errorInfo=nil; 
NSString *[email protected]"tell application \"Mail\"\nget name of mailbox of every account\nend tell"; 
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:source]; 
NSAppleEventDescriptor *aDescriptor=[[NSAppleEventDescriptor alloc]init]; 
aDescriptor=[run executeAndReturnError:&errorInfo]; 
[aDescriptor coerceToDescriptorType:'utxt']; 
NSLog(@"result:%@",[aDescriptor stringValue]); 

輸出,我得到: 結果:(空)

請幫我人在這。提前感謝:)

回答

3

IIRC將返回列表描述符填充列表描述符。你需要遍歷它們並提取你想要的信息。您還正在初始化一個描述符,然後立即覆蓋它的指針。做一些像(未經測試):

NSDictionary *errorInfo = nil; 
NSString *source = @"tell application \"Mail\"\nget name of mailbox of every account\nend tell"; 
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:source]; 
NSAppleEventDescriptor *aDescriptor = [run executeAndReturnError:&errorInfo]; 
NSInteger num = [aDescriptor numberOfItems]; 

// Apple event descriptor list indexes are one-based! 
for (NSInteger idx = 1; idx <= num; ++idx) { 
    NSAppleEventDescriptor *innerListDescriptor = [aDescriptor descriptorAtIndex:idx]; 

    NSInteger innerNum = [innerListDescriptor numberOfItems]; 

    for (NSInteger innerIdx = 1; innerIdx <= innerNum; ++innerIdx) { 
     NSString *str = [[innerListDescriptor descriptorAtIndex:innerIdx] stringValue]; 
     // Do something with str here 
    } 
}