title: How to return a list of objects from an NSScriptCommand subclass's performDefaultImplementation?
body: <p>I am adding a verb-first AppleScript command in a Cocoa application. The sdef command definition indicates that the command returns a list of text strings:</p>
  
  <pre><code>&lt;command name="list names" code="ABCDLstN" description="return a list of names"&gt;
      &lt;cocoa class="ListNamesCommand"/&gt;
      &lt;result type="text" list="yes" description="some names"/&gt;
  &lt;/command&gt;
  </code></pre>
  
  <p>The <code>ListNamesCommand</code> class's <code>performDefaultImplementation</code> method returns an <code>NSArray</code> of <code>NSString</code>:</p>
  
  <pre><code>- (id)performDefaultImplementation {
      return @[@"name 1", @"name 2"];
  }
  </code></pre>
  
  <p>The result is an exception:</p>
  
  <pre><code>2013-12-17 17:22:37.474 ListNames[31907:303] Error while returning the result of a script command: the result object...
  (
      name1,
      name2
  )
  ...could not be converted to an Apple event descriptor of type 'text'. This instance of the class '__NSArrayI' doesn't respond to -scriptingTextDescriptor messages.
  </code></pre>
  
  <p>A <a href="http://lists.apple.com/archives/applescript-implementors/2005/Sep/msg00052.html" rel="nofollow">workaround</a> is to change the sdef to specify the result type as <code>any</code> rather than <code>text</code>, and return an NSAppleEventDescriptor instead of an NSArray:</p>
  
  <pre><code>- (id)performDefaultImplementation {
      NSAppleEventDescriptor *list = [NSAppleEventDescriptor listDescriptor];
      [list insertDescriptor:[NSAppleEventDescriptor descriptorWithString:@"name 1"] atIndex:1];
      [list insertDescriptor:[NSAppleEventDescriptor descriptorWithString:@"name 2"] atIndex:2];
  
      return list;
  }
  </code></pre>
  
  <p>However, this has the unfortunate side-effect of documenting the event (in the AppleScript Editor dictionary viewer) as returning any type.</p>
  
  <p>Is there a solution that does not have that drawback?</p>