Apply Cocoa App to a Simple AppleScript Command

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:

 #import <Cocoa/Cocoa.h> @interface rdrNotifierUpdateCommand : NSScriptCommand { } -(id)performDefaultImplementation; @end 

Implementation:

 #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 

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"> <!-- I have removed the standard suite as the application does not open, print... --> <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"> <!-- Note you need to specify a method here, although it is blank --> <cocoa method=""/> </responds-to> </class> </suite> </dictionary> 

Any improvements / tips / criticisms are still welcome.

+6
source share
1 answer

Thank you for adding applescript support to your application! Just a quick observation / criticism: when constructing a terminology, by all means, there are gaps, but if this terminology takes the form of a "verb noun" (for example, "update"), appleScript developers will be annoyed if updating the "noun" is not correct and if "do" is not a proper command.

I would say that โ€œdoโ€ is a bad choice for a team name because it is very vague. What happened with using "update" as a command? (i.e. treat it as a verb).

This issue is addressed in detail by Apple's proprietary 2106 technologists (currently here ), which you should definitely read and digest if you are hoping to contact the AppleScripting user community.

Apple itself does not go beyond silly terminology solutions such as updatePodcast and updateAllPodcasts (in iTunes). This is a stupid choice, because (according to tn2106) they do not contain spaces, but because the best choice would be to have the correct podcast class, and then the update command, which can be used in a separate podcast, all podcasts, or a specific selected set of podcasts.

+2
source

Source: https://habr.com/ru/post/888126/


All Articles