Re: The Future (ASS, ASOC, Cocoa + AS)
Re: The Future (ASS, ASOC, Cocoa + AS)
- Subject: Re: The Future (ASS, ASOC, Cocoa + AS)
- From: Shane Stanley <email@hidden>
- Date: Tue, 04 May 2010 11:06:19 +1000
- Thread-topic: The Future (ASS, ASOC, Cocoa + AS)
On 1/5/10 12:04 AM, "Hagimeno" <email@hidden> wrote:
> Is possible using Cocoa to invoke AppleScript? We think yes but this is robust
> implementation or is complicated? I mean more complicated that do this in ASS
> or ASOC.
> There is an example of AS routine invoked by Cocoa app?
> Just a short example that explain how to pass parameters and how the result
> are returned to Cocoa app.
So here's a handler in an AS script called ASController:
on doCountry_PMRPath_lineFeedCode_(theCountry, pmrFolderPath, linefeedCode)
set theCountry to theCountry as text -- coerce it to AS class
[...]
end doCountry_PMRPath_lineFeedCode_
The Objective-C class's header file has an @class statement for the AS class
and an IBOutlet connected to the script instance in Interface Builder:
#import <Cocoa/Cocoa.h>
@class ASController;
@interface AppController : NSObject {
IBOutlet ASController *AScontroller;
[...]
And the call in the implementation file is:
[AScontroller doCountry:[self country] PMRPath:[self pathOfPMR]
lineFeedCode:@"<Newline/>"];
In other words, it's much like calling a method in an Objective-C instance,
and you handle results in the same way. Text, numbers, booleans, lists and
records will translate to their Objective-C equivalents automagically.
You can also call AS handlers as class methods, if you don't want/need to
instantiate them.
The only catch is that you will get compiler warnings because AS methods'
parameters are typed as id by default, but you can ignore them, or fix them
by including suitable method signatures in an Objective-C formal protocol.
And of course it's 10.6 and later only.
--
Shane Stanley <email@hidden>
_______________________________________________
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