How to Extract AppleScript Data from a NSAppleEventDescriptor in Cocoa and Parse it

元气小坏坏 提交于 2019-11-28 01:13:30

问题


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'() }>

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! :)


回答1:


[[aDescriptor descriptorForKeyword:keyAEKeyData] stringValue]



回答2:


That's a record, not a list. Try descriptorForKeyword:, passing the constant matching the four-character code you want. (The constants are declared in the Apple Events headers.)



来源:https://stackoverflow.com/questions/1247013/how-to-extract-applescript-data-from-a-nsappleeventdescriptor-in-cocoa-and-parse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!