Re: Trying to create an sdef
Re: Trying to create an sdef
- Subject: Re: Trying to create an sdef
- From: Shane Stanley <email@hidden>
- Date: Thu, 07 Aug 2014 21:52:43 +1000
On 7 Aug 2014, at 8:45 pm, Gerriet M. Denkmann <email@hidden> wrote:
> Now the AppDelegate also has a method: -(void)selectWordsContaining: (NSString *)s which results in not showing all words, but only those containing the given string.
>
> And I want to write a script like:
>
> tell application "App"
> selectWordsContaining "good"
> end tell
>
> But nothing happens, no output, no error message and my method is never called.
> Obviously something is missing. But what?
First off, you should write the command as "select words containing" -- in AppleScript terminology you don't jam words together. (You might be better off using "select words", with a parameter called "containing". But for now...)
There are two types of commands: verb-first and object-first. It looks like you want an object-first command. You can't do this in your app delegate -- you need it in the object you're addressing. Your method in your NSApplication category then becomes something like this:
-(void) selectWordsContaining:(NSScriptCommand *)command {
NSString *theWord = [command directParameter];
...
> The sdef is:
>
> <suite name="App Suite" code="Apps" description="Classes just for the App application.">
> <class name="application" code="capp" description="The application class.">
> <cocoa class="NSApplication"/>
>
> <element type="word" access="r">
> <cocoa key="wordsArray"/>
> </element>
>
> <responds-to name="selectWordsContaining">
> <cocoa method="selectWordsContaining:"/>
> </responds-to>
> </class>
>
> <class name="word" code="claL" description="One of our list of words">
> <cocoa class="NSString"/>
> <type type="text"/>
> </class>
>
> <command name="selectWordsContaining" code="LaksLaks" description="Show only words containing...">
> <direct-parameter type="text" description="The string."/>
> </command>
> </suite>
You shouldn't redefine the AppleScript term word, especially giving it a new code. Either use the (lame) Text Suite, or define your own term.
Before you go any further, I suggest you read Technical Note TN2106. Some of it is out of date, but it has a lot of good advice on designing a scripting interface.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden