2011-11-10 130 views
1

我有一個測試AppleScript字典:腳本Cocoa應用程序

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> 

<dictionary title="ScriptTest Terminology"> 

    <suite name="Standard Suite" code="????" description="Common classes and commands for all applications."> 
     <class name="application" code="capp" description="The application's top-level scripting object."> 
      <cocoa class="NSApplication"/> 
     </class> 
    </suite> 


    <suite name="MyApplication Suite" code="scts" description="MyApplication information."> 
     <class name="application" code="capp" description="The application's top-level scripting object." inherits="application"> 
      <cocoa class="NSApplication"/> 

      <responds-to command="sayhello"> 
       <cocoa method="sayHello:"/> 
      </responds-to> 

     </class> 

     <command name="sayhello" code="sctshell" description="Says hello."> 
     </command> 
    </suite> 

</dictionary> 

我的AppDelegate有方法:

- (void)sayHello:(NSScriptCommand*)scriptCommand; 

但它永遠不會被調用。爲什麼?

如何在appleScript中將命令添加到我的應用程序類中? (例如tell application "Test" to sayhello)?

回答

0

請看Apple的SimpleScriptingVerbs示例代碼。該命令的SayHello你sdef定義應命名的NSScriptCommand實現該命令的子類:

<command name="sayhello" code="sctshell" description="Says hello."> 
    <cocoa class="SayHelloCommand"/> 
</command> 

然後實現SayHelloCommand作爲NSScriptCommand子類,並覆蓋其performDefaultImplementation方法。