Objective c 如何从Cocoa中的NSAppleEventDescriptor中提取AppleScript数据并对其进行解析
我所做的是在Cocoa内部执行AppleScript。它以NSAppleEventDescriptor的形式返回一些数据,NSLog()按如下方式打印:Objective c 如何从Cocoa中的NSAppleEventDescriptor中提取AppleScript数据并对其进行解析,objective-c,cocoa,applescript,appleevents,Objective C,Cocoa,Applescript,Appleevents,我所做的是在Cocoa内部执行AppleScript。它以NSAppleEventDescriptor的形式返回一些数据,NSLog()按如下方式打印: <NSAppleEventDescriptor: 'obj '{ 'form':'name', 'want':'dskp', 'seld':'utxt'("69671872"), 'from':'null'() }> 提前感谢您的帮助!:) 这是记录,不是列表。请尝试描述符workeyword:,传递与所需四字符代码匹配的常量。(
<NSAppleEventDescriptor: 'obj '{ 'form':'name', 'want':'dskp', 'seld':'utxt'("69671872"), 'from':'null'() }>
提前感谢您的帮助!:) 这是记录,不是列表。请尝试
描述符workeyword:
,传递与所需四字符代码匹配的常量。(常量在Apple事件标题中声明。)我无法让Peter Hosey的解决方案在包装为NSAppleEventDescriptor的AppleScript列表中工作。相反,我找到了以下解决方案,将列表强制为ObjC数组:
NSAppleEventDescriptor *listDescriptor = [result coerceToDescriptorType:typeAEList];
NSMutableArray *thisArray = [[NSMutableArray alloc] init];
for (NSInteger i = 1; i <= [listDescriptor numberOfItems]; ++i) {
NSAppleEventDescriptor *stringDescriptor = [listDescriptor descriptorAtIndex:i];
[thisArray addObject: stringDescriptor.stringValue];
}
NSLog(@"array result: %@", thisArray);
NSAppleEventDescriptor*listDescriptor=[结果强制描述符类型:typeAEList];
NSMutableArray*thisArray=[[NSMutableArray alloc]init];
因为(NSInteger i=1;我非常感谢!:)这看起来太简单了。我想我有很多东西要学@彼得·霍西(Peter Hosey)感谢你不断的更换(我应该知道)。啊,太好了。非常感谢!:)
[[aDescriptor descriptorForKeyword:keyAEKeyData] stringValue]
NSAppleEventDescriptor *listDescriptor = [result coerceToDescriptorType:typeAEList];
NSMutableArray *thisArray = [[NSMutableArray alloc] init];
for (NSInteger i = 1; i <= [listDescriptor numberOfItems]; ++i) {
NSAppleEventDescriptor *stringDescriptor = [listDescriptor descriptorAtIndex:i];
[thisArray addObject: stringDescriptor.stringValue];
}
NSLog(@"array result: %@", thisArray);