gpt4 book ai didi

objective-c - 无法解析 NSAppleScript 方法executeAndReturnError返回的结果

转载 作者:行者123 更新时间:2023-12-03 16:32:55 25 4
gpt4 key购买 nike

这是我正在使用的代码:

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]);

我得到的输出:结果:(空)

请任何人帮助我。提前致谢:)

最佳答案

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
}
}

关于objective-c - 无法解析 NSAppleScript 方法executeAndReturnError返回的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7833711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com