首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析NSAppleEventDescriptor中的一段简单文本

解析NSAppleEventDescriptor中的一段简单文本
EN

Stack Overflow用户
提问于 2011-07-22 02:32:07
回答 1查看 1.9K关注 0票数 0

因此,我有一个简单的applescript,它返回(返回"test")以下内容:

测试:‘utxt’(“NSAppleEventDescriptor”)

我发现了this问题,并尝试用下面的代码复制它所做的事情

代码语言:javascript
复制
NSAppleScript *scriptObject = [[NSAppleScript alloc]initWithContentsOfURL:[NSURL fileURLWithPath: scriptPath]
                                                                    error:&error];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
NSLog(@"Return Discriptor,%@",returnDescriptor);

NSAppleEventDescriptor *utxt = [returnDescriptor descriptorForKeyword:'utxt'];
NSLog(@"Found utxt Discriptor: %@",utxt);

NSString *scriptReturn = [utxt stringValue];
NSLog(@"Found utxt string: %@",scriptReturn);

但它没有返回任何内容:

返回描述符,找到utxt描述符:(null)找到utxt字符串:(null)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-22 07:54:11

在我看来,returnDescriptor已经是描述符了,你不需要这个: returnDescriptor descriptor descriptor:‘utxt’;。我没有测试这段代码,但试一试...

代码语言:javascript
复制
NSDictionary *errorDict = nil;
NSAppleScript *scriptObject = [[NSAppleScript alloc]initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:&errorDict];
if (errorDict) {
   NSLog(@"Error: %@", errorDict);
   return;
}
NSAppleEventDescriptor *returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
if (errorDict) {
   NSLog(@"Error: %@", errorDict);
   [scriptObject release];
   return;
}

NSString *scriptReturn = [returnDescriptor stringValue];
NSLog(@"Found utxt string: %@",scriptReturn);
[scriptObject release];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6780910

复制
相关文章

相似问题

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