Re: Executing AppleScript from Cocoa (with return values)
Re: Executing AppleScript from Cocoa (with return values)
- Subject: Re: Executing AppleScript from Cocoa (with return values)
- From: cricket <email@hidden>
- Date: Mon, 18 Aug 2003 14:31:18 -0700
I use this method in a context where everything I'm getting back from
AppleScript is a list of items. So, even if my result is just one item,
it's coming from AppleScript as something like {"1"}. AppleScript sees
the whole item as a descriptor containing one descriptor, which can be
coerced to a string. Something like {"2", "3"} is a descriptor
containing two descriptors, each of which can be coerced to strings.
This method never gets called with a descriptor that doesn't contain
other descriptors.
Does that help?
- cricket
On Monday, August 18, 2003, at 2:25 PM, email@hidden wrote:
Ah, so this will keep the hierarchy of lists of lists [of lists [of
lists
[...]]] of strings intact, correct? Pretty neat. I assume that you
could
expand this to represent returned AppleScript records as
NSMutableDictionary
objects within the hierarchy. For the application I have in mind,
though, I
can manage with a list of lists.
I'm curious, though. Why do you resend [descriptor
descriptorAtIndex:counter]
inside the else block when the result should already be in desc? Am I
missing
something?
I use this class method to turn an NSAppleEventDescriptor into an
array
of strings. Note that descriptorAtIndex: is 1-based, not 0-based.
+ (NSArray *)arrayFromDescriptor:(NSAppleEventDescriptor *)descriptor
{
NSMutableArray *returnArray = [NSMutableArray array];
int counter, count = [descriptor numberOfItems];
for (counter = 1; counter <= count; counter++) {
NSAppleEventDescriptor *desc = [descriptor
descriptorAtIndex:counter];
if (nil != [desc descriptorAtIndex:1]) {
[returnArray addObject:[self arrayFromDescriptor:desc]];
} else {
NSString *stringValue = [[descriptor
descriptorAtIndex:counter] stringValue];
if (nil != stringValue) {
[returnArray addObject:stringValue];
} else {
[returnArray addObject:@""];
}
}
}
return (NSArray *)returnArray;
}
----->
Software Entomologist Mail for Mac OS X
http://www.apple.com/macosx/panther/mail.html
---------->
My marbled brisket; Glistening with marinade; Atop my head, displayed
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.