首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法分析NSAppleScript方法executeAndReturnError返回的结果

无法分析NSAppleScript方法executeAndReturnError返回的结果
EN

Stack Overflow用户
提问于 2011-10-20 17:21:03
回答 1查看 1.7K关注 0票数 2

这是我使用的代码:

代码语言:javascript
复制
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=[[NSAppleEventDescriptor alloc]init];
aDescriptor=[run executeAndReturnError:&errorInfo];
[aDescriptor coerceToDescriptorType:'utxt'];
NSLog(@"result:%@",[aDescriptor stringValue]);

我得到的输出: result:(null)

请提前在this.Thanks上帮助我:)

EN

回答 1

Stack Overflow用户

发布于 2011-10-20 17:53:41

IIRC,它将返回一个用列表描述符填充的列表描述符。你需要遍历它们并提取出你想要的信息。您还初始化了一个描述符,然后立即覆盖了它的指针。做一些类似的事情(未测试):

代码语言:javascript
复制
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
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7833711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档