title: Make Cocoa application respond to simple AppleScript command
body: <p>I am trying to add a trivial AppleScript support to a Cocoa application. The application performs a check periodically and I just want to be able to tell it to perform it on demand.</p>
  
  <p>I am trying to follow the <a href="http://developer.apple.com/mac/library/samplecode/SimpleScriptingVerbs/" rel="nofollow">SimpleScriptingVerbs</a> Apple example.</p>
  
  <p>I have subclassed <code>NSScriptCommand</code> as follows:</p>
  
  <p>Header:</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  
  @interface rdrNotifierUpdateCommand : NSScriptCommand {
  
  }
  -(id)performDefaultImplementation;
  @end
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>#import "rdrNotifierUpdateCommand.h"
  #import "rdrNotifierAppDelegate.h"
  
  @implementation rdrNotifierUpdateCommand
  
  -(id)performDefaultImplementation {
    NSLog(@"Works at last");
    [((rdrNotifierAppDelegate *)[[NSApplication sharedApplication] delegate])
     checkForNewItems];  // This just fires the timer
    return nil;
  }
  @end
  </code></pre>
  
  <p>My <code>.sdef</code> file goes as follows (and the problem seems to be there, but I cannot find it):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"&gt;
  &lt;dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude"&gt;
      &lt;xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/&gt;
      &lt;suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities."&gt;
          &lt;command name="do update" code="rdrNUpdt" description="Check for new items"&gt;
              &lt;cocoa class="rdrNotifierUpdateCommand"/&gt;
          &lt;/command&gt;
      &lt;/suite&gt;
  &lt;/dictionary&gt;
  </code></pre>
  
  <p>The <code>Info.plist</code> is set up appropriately.</p>
  
  <p>But, when I try to run the following script in AppleScript editor:</p>
  
  <pre><code>tell application "rdrNotifier"
      do update
  end tell
  </code></pre>
  
  <p>I receive an error about variable "update" not being defined.</p>
  
  <p>I can open the dictionary for my application from AppleScript Editor (i.e. it is successfully registered).</p>
  
  <p><strong>Edit: Found a solution</strong></p>
  
  <p>The problem was indeed in the <code>sdef</code> file: I was not specifying that the application can reply to the command. My final definition goes as follows (Obj-C code unchanged):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"&gt;
  &lt;dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude"&gt;
    &lt;!-- I have removed the standard suite as the application does not open, print... --&gt;
    &lt;suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities."&gt;
      &lt;command name="do update" code="rdrNUpdt" description="Check for new items"&gt;
        &lt;cocoa class="rdrNotifierUpdateCommand"/&gt;
      &lt;/command&gt;
      &lt;class name="application" code="Capp"&gt;
        &lt;cocoa class="NSApplication"/&gt;
        &lt;responds-to name="do update"&gt;
          &lt;!-- Note you need to specify a method here,
               although it is blank --&gt;
          &lt;cocoa method=""/&gt;
        &lt;/responds-to&gt;
      &lt;/class&gt;
    &lt;/suite&gt;
  &lt;/dictionary&gt;
  </code></pre>
  
  <p>Any improvements/tips/criticisms are still welcome.</p>