On 7 Aug 2014, at 12:41 am, Gerriet M. Denkmann <[email protected]> wrote:

> Apple Script Editor can do:
> 
> tell application "B"
>       get version
> end tell

And so can your app. Add AppleScriptObjC.framework to your target, and add this 
to main.m:

    [[NSBundle mainBundle] loadAppleScriptObjectiveCScripts];

Add a new file (choose Empty) to the project, call it SomeName.applescript, and 
in it add:

script SomeName
        property parent : class "NSObject"

on appVersion()
 tell application "B"
  set theVers to version
 end tell
 return theVers
end appVersion

end script

Now add an informal protocol to your calling class that includes:

- (NSString *)appVersion

And you can call it something like:

NSString *version = [NSClassFromString(@"SomeName") appVersion];

There are a few things to watch: you should only pass objects, and the bridge 
only converts NSStrings/text, NSNumbers/reals/integers, NSArrays/lists and 
NSDictionaries/records. And if you pass variables to the script, it needs to 
coerce them to their AppleScript equivalents.

For one or two commands, ScriptingBridge might be easier. But for more complex 
stuff, ASObjC avoids the whole hassle of building and maintaining the app 
header file, and can do some stuff more efficiently than SBApplication et al 
can.


-- 
Shane Stanley <[email protected]>
<www.macosxautomation.com/applescript/apps/>


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to