I am trying to add trivial AppleScript support to a Cocoa application. The application periodically checks, and I just want to say that it runs it on demand.
I am trying to follow Apple's SimpleScriptingVerbs example.
I have subclassed NSScriptCommand as follows:
Title:
Implementation:
#import "rdrNotifierUpdateCommand.h" #import "rdrNotifierAppDelegate.h" @implementation rdrNotifierUpdateCommand -(id)performDefaultImplementation { NSLog(@"Works at last"); [((rdrNotifierAppDelegate *)[[NSApplication sharedApplication] delegate]) checkForNewItems];
My .sdef file looks like this (and the problem seems to be there, but I can't find it):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> <dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude"> <xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/> <suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities."> <command name="do update" code="rdrNUpdt" description="Check for new items"> <cocoa class="rdrNotifierUpdateCommand"/> </command> </suite> </dictionary>
Info.plist configured accordingly.
But, when I try to run the following script in the AppleScript editor:
tell application "rdrNotifier" do update end tell
I get an โupdateโ error message that is not defined.
I can open the dictionary for my application from the AppleScript editor (i.e. it is successfully registered).
Edit: solution found
The problem really was in the sdef file: I did not indicate that the application could respond to the command. My final definition is as follows (Obj-C code unchanged):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> <dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude"> <suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities."> <command name="do update" code="rdrNUpdt" description="Check for new items"> <cocoa class="rdrNotifierUpdateCommand"/> </command> <class name="application" code="Capp"> <cocoa class="NSApplication"/> <responds-to name="do update"> <cocoa method=""/> </responds-to> </class> </suite> </dictionary>
Any improvements / tips / criticisms are still welcome.