如何从 Cocoa 中的 NSAppleEventDescriptor 中提取 AppleScript 数据并解析它 [英] How to Extract AppleScript Data from a NSAppleEventDescriptor in Cocoa and Parse it

查看:30
本文介绍了如何从 Cocoa 中的 NSAppleEventDescriptor 中提取 AppleScript 数据并解析它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做的是在 Cocoa 中执行 AppleScript.它将一些数据作为 NSAppleEventDescriptor 返回,NSLog() 打印如下:

What I'm doing is executing an AppleScript inside of Cocoa. It returns some data as a NSAppleEventDescriptor, which NSLog() prints like so:

<NSAppleEventDescriptor: 'obj '{ 'form':'name', 'want':'dskp', 'seld':'utxt'("69671872"), 'from':'null'() }>

我想获取这些数据并将其转换为 NSDictionaryNSArray,或者一些有用的东西,以便我可以从中提取内容(特别是我在该领域之后持有69671872"号码).它似乎是某种数组,但我对 Apple Events 的了解相当有限.知道如何做到这一点吗?

I want to take that data and turn it into a NSDictionary or NSArray, or something useful so I can extract stuff from it (specifically I'm after the field holding the "69671872" number). It appears to be an array of some sort, but my knowledge with Apple Events is fairly limited. Any idea on how to do this?

这是创建上述数据的来源:

Here's the source creating the above data:

NSString *appleScriptSource = [NSString stringWithFormat:@"tell application\"System Events\"\n return desktop 1\n end tell"];
NSDictionary *anError;
NSAppleScript *aScript = [[NSAppleScript alloc] initWithSource:appleScriptSource];
NSAppleEventDescriptor *aDescriptor = [aScript executeAndReturnError:&anError];

NSLog (@"%@", aDescriptor);
[aScript release];

在此先感谢您的帮助!:)

Thanks in advance for any help! :)

推荐答案

[[aDescriptor descriptorForKeyword:keyAEKeyData] stringValue]

这篇关于如何从 Cocoa 中的 NSAppleEventDescriptor 中提取 AppleScript 数据并解析它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆