@implementation NSArray (Scriptability)
// build a list descriptor from an NSArray of NSStrings
- (NSAppleEventDescriptor *)scriptingTextDescriptor
{
NSAppleEventDescriptor *desc = [NSAppleEventDescriptor listDescriptor];
for (unsigned int i = 0; i < self.count; i++)
{
NSString *item = self[i];
NSAppleEventDescriptor *itemDesc
= [NSAppleEventDescriptor descriptorWithString:item];
[desc insertDescriptor:itemDesc atIndex:i+1]; // AEDesc are 1-based
}
return desc;
}
// build a list descriptor from an NSArray of integers
- (NSAppleEventDescriptor *)scriptingIntegerDescriptor
{
NSAppleEventDescriptor *desc = [NSAppleEventDescriptor listDescriptor];
for (unsigned int i = 0; i < self.count; i++)
{
SInt32 item = [self[i] intValue];
NSAppleEventDescriptor *itemDesc
= [NSAppleEventDescriptor descriptorWithInt32:item];
[desc insertDescriptor:itemDesc atIndex:i+1]; // AEDesc are 1-based
}
return desc;
}
@end
You could add similar methods to this category for other data types. The naming pattern is -scripting<TYPE>Descriptor