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: Fri, 08 Aug 2014 17:54:52 +1000
On 8 Aug 2014, at 5:07 pm, Gerriet M. Denkmann <email@hidden> wrote:
> 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.
OK, then you need to build a header file for your scriptable app. That requires using sdef and sdp on the command line -- look in the Xcode docs for 'Using Scripting Bridge' (I prefer using AppleScriptObjC, but that probably reflects my background. It's also easier if your scriptable app's dictionary is a moveable target, because you don't have to keep building new header files for it. Whatever.)
> 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.
You add options as parameters, giving them appropriate keys in the sdef file -- look in a sample sdef and that part should be pretty obvious. Change your method from void to id or whatever. Just remember to return one of the bridged classes. So your method becomes:
-(id)doWhatever:(NSScriptCommand *)command {
NSString *someParam = [[command evaluatedArguments] valueForKey:@"theCocoaKeyYouUsedInTheSdef"];
...
return someString;
}
Assuming you set a type of "text" for both the parameter and the command's result, it should all just work.
>
> 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?
The AppleScript equivalent of an NSDictionary is a record, and the two are bridged (records can also store other stuff, but that shouldn't matter to you). One thing you need to be aware of is that dictionary values of [NSNull null] aren't bridged in 10.9; the value and its key will just get dropped. Similarly AppleScript values of the rough equivalent (missing value) exhibit the same behavior. I've only struck this in AppleScriptObjC, but I suspect ScriptingBridge will do the same thing.
But otherwise, this:
@{@"someKey":@"someValue"}
will end up in AS as:
{someKey:"someValue"}
To extract the value, you use:
someKey of theRecord
--
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