calling Objective C method from AppleScriptObjC


I have a applescript routine that I need to speed up so to make it C.

I’m trying then to call a ObjC Method that would optimize my AppleScript routines.

In despite of reading the AppleScriptObjC Release Notes and some tutorials and forum on this subject I 'm still failing.

I have made a simple class to start with.

#import <Cocoa/Cocoa.h>

@interface RawTestFile : NSObject {

// Methods
-(void) create;

#import “RawTestFile.h”

@implementation RawTestFile
-(void) create {
NSLog(@“Hi !!”);

and in my AppleScriptObjC application delegate

script FooAppDelegate
	property parent : class "NSObject"
	property myRawTestFile : class "RawTestFile"

        on bench_(sender)
        myRawTestFile's create_()

        end bench_

end script

when myRawTestFile’s create_() executes I got an error
+[RawTestFile create:]: unrecognized selector sent to class 0x1000010a0 (error -10000)

Looks like I have no instance, so I assume property does not instantiate my class.

I also tried this

set myRawTestFile to RawTestFile()
myRawTestFile's create_()

thinking that myRawTestFile would be an instance of RawTestFile.

so how to I instantiateRawTestFile class within applescript ?


Well at first glance I’d say RawTestFile≠myRawTestFile, try my RawTestFile and come back.

Edit: you could try

tell current application's class myclass to dosubroutine()

Very important also that if a subroutine calls no variables do not put an underscore!

You can either instantiate it in Interface Builder – drag in an NSObject blue cube and change its class, make a property set to missing value, and make the variable an outlet of the instance – or use “set oneTestObject to myRawTestFile’s alloc()'s init()”. And as Richard says, don’t use an underscore for methods that don’t take an argument.

Thanks to all.

I succeed to make it work.

I have instantiated the class in applescript code as suggested by Shane.

So here is the code that works.

		set myRawTestFile to RawTestFile's alloc()'s init()
		myRawTestFile's create()

I really need to use myRawTestFile as it is the instance and RawTestFile is the class.

this code below still throw an unrecognized selector sent to class error

		RawTestFile's alloc()'s init()
		RawTestFile's create()