Re: Talking to other apps - again
Re: Talking to other apps - again
- Subject: Re: Talking to other apps - again
- From: Shane Stanley <email@hidden>
- Date: Thu, 07 Aug 2014 10:34:40 +1000
On 7 Aug 2014, at 12:41 am, Gerriet M. Denkmann <email@hidden> 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@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden