Re: Trying to create an sdef
Re: Trying to create an sdef
- Subject: Re: Trying to create an sdef
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 08 Aug 2014 14:07:38 +0700
On 7 Aug 2014, at 18:52, Shane Stanley <email@hidden> wrote:
>
> 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...)
Ok. Done.
>
> 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.
Sorry. I edited the stuff to get rid of unnecessary details. I was not aware that "word" already has a fixed meaning in the Text Suite.
Let's call it "thing" instead.
> 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.
Just finished reading.
Following your suggestions I moved selectWordsContaining: to my NSApplication category and now everything is fine.
(Until the next problem will arise.)
By the way, I read your posting in CocoaDev Re: Talking to other apps - again.
You wrote: "For one or two commands, ScriptingBridge might be easier." What I plan to send is just one command.
This is the next step:
Make App A send "do something with the supplied string (and maybe some options) and expect a string back" to the App which just is learning to be scriptable.
Or even better: A sends a dictionary (containing just strings) to B and B returns another dictionary back to A.
This would be the only command needed.
Which leads to the next question: are dictionaries something which fit into Apple Script more or less naturally, or would this be a major pain?
Thanks again for your help!
Kind regards,
Gerriet.
_______________________________________________
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