I'm trying to make my application scriptable, and one of the things that I'd like to be able to do is return an array from my application and into AppleScript so that it can be processed further there. I suppose I could do this by returning the count for the array, and then having AppleScript iterate from 1 to n to return each item from the array - but I don't think that this would be very efficient.
My code currently looks like this:
Relevant section of the sdef file
<command name="List" code="lflecont" description="List file types found in data stream">
<cocoa class="ListDataContentCommand"/>
<result description="an array containing the types of all the data blocks in the File">
<type type="any" list="yes"/>
</result>
</command>
ListDataContentCommand.h
@interface ListDataContentCommand : NSScriptCommand
@end
ListDataContentCommand.m
@implementation ListDataContentCommand
-(id)performDefaultImplementation {
return @[@"Jam",@"Fish",@"Eggs"];
}
@end
To test this, I've created the following simple AppleScript…
tell application "Data Dump"
open "/Volumes/Test Data/test.dat"
set theList to List
end tell
This returns an error - error "Data Dump got an error: Can’t continue List." number -1708
How can I get my array to be output?
For that matter, how can NSDictionary be returned? Or is that impossible? And can NSString be returned straight to text - or does it need to be converted to a Cstring first?
Newbie questions, I'm afraid, but good information on AppleScript seems to be quite hard to come by!
NSString,NSNumberandNSDateare bridged implicitly to the AppleScript types. By default AppleScript works synchronous, theListDataContentCommandscript command returnsnil(missing valueon the AppleScript side). If you need asynchronous processing you have to callsuspendandresumeon the current script command. And what is the real return type? If you useanyyou have to returnNSAppleEventDescriptor. To return a dictionary you have to create arecord-typein the sdef file.list="yes". And theidreturn type covers alsoNSArray