I’m trying to call an instance method from AppleScript Studio. I read http://www.macscripter.net/viewtopic.php?id=29285 and I thought I could just steal StefanK’s sharedInstance but I can’t get that to work…
This is my AppleScript code:
set sharedInstance to call method "sharedInstance" of class "AppController"
call method "flushVideoInformation" of sharedInstance
(void)flushVideoInformation {
[videoHeader setStringValue:@“”];
} @end[/code]
I know you’re all thinking like, “Hey, you can just do that in AppleScript Studio without Objective-C!”, but this is just an example, the original code is larger.
My Error : “No result was returned from some part of this expression.” (-2763)
I guess you have to implement the init method, which initializes the instance calling the super class.
It’s not necessary to declare the method in the .h file
I created an instance just to access those IBOutlets and that I didn’t had to pass them from AppleScript. I though ObjC would have had something like in AppleScript text field 1 of window 1. You know, the path. But as far as I know it hasn’t and I wanted to use IBOutlets so I didn’t have to pass all the parameters.
I tested it (on Leopard) with a sample project, same behavior. It does not work
A workaround is to write set accessors for the UI elements like
-
(void)assignTextField:(NSTextField *)f
{
field = f;
}
and pass the references after initializing the instance
set instance to call method "sharedInstance" of class "myClass"
call method "assignTextField:" of instance with parameter (a reference to text field "textfield" of window "main")
Do you think I can’t access them because it’s how ObjC works or because I use AppleScript Studio to first create the instance ?
I really hoped that ObjC had something like
text field "textField" of window "main"
But it seems I either have to use IBOutlets or pass them from AppleScript. That makes me think, since Apple’s apps aren’t written in AppleScript, they can’t pass them from it so they have to use ObjC. So, in an instance they access the element somehow different. That’s why I thought something like the script above would exist in ObjC
I have an idea, what if I call sharedInstance from within ObjC (from i.e. awakeFromNib) maybe it will work then. I don’t know how to use awakeFromNib in ObjC but I’ll check on it tomorrow. Can’t be too hard…