inter-script communication questions

Hi ALL,

I am in process of splitting up my main script into smaller scripts. I have been reading about MVC in Docs but getting a bit confused how to convert my scripts along those lines. Hopefully Craig’s MVC movie will help.

My concern is being able to communicate between script classes.

If we access an applescript class from another script without using a blue cube for that class, what are we accessing? An instance of that script?

What about If we access an applescript class from another script via a blue cube, which is called I believe, an instance of that class.

What is the difference between the two?

Either way, I seem to be able to call a handler and pass it variables. Setting another script class’s properties get’s trickier

so I have myController script and myHandleTheData script.

I want to set some properties to initialize the myHandleTheData script before calling it’s handlers.

I set up a blue cube for myHandleTheData and can set it’s properties by calling a handler

script myHandleTheData

property parent : class "NSObject"
property someProp:""

on displayResult()
display dialog someProp
end

end script

then in main script

script myController

property parent : class "NSObject"
property myHandleTheData: missing value

on testItOut_(sender)

set myHandleTheData's someProp to "say hello"  -- this doesn't work

myHandleTheData's setSomeProp_("say hello")  -- this doesn't work either (like it did for Shane's setTheFruit prop.)

myHandleTheData's displayResult_()  -- displays ""
end testItOut_

end script

Is there a way to set its properties? I think we already talked about this but can’t find the thread.

Thanks, Rob

PS This all points to my lack of understanding about how OBJ-C classes, instances, MVC and ASOC relate…

In Obj-C those value() and setValue_() methods are just handlers named after their getting and setting characteristics, adding set doesn’t change a property. Add handlers like:

on setSomeProp_(newProp)
set someProp to newProp
end setSomeProp_

on someProp()
return someProp
end someProp

But you can name them what ever you like, beware with inter-script stuff you must have one underscore per parameter just like any other Obj-C method, doesn’t matter what order though.

Thanks Richard,

I actually tried that first and it didn’t work. Now it does! Go figure.

I did realize too I had to set the someProp var to string before display dialog.

Rob

Actually, it does change the property. The value() and setValue() are called using the key value coding system. You can implement your own version of these and override the setValue() method but it is not necessary unless you are doing something with the value before returning it.

There is a video on my website that goes over KVC.

How does it tell property methods apart from others?

So one can set another script’s properties with “set”? It doesn’t seem to work with

set myHandleTheData's someProp to "say hello"

rob

If Craig is right he means the value() and setValue_() way, but this is confusing, at least from an AppleScript perspective.

You are right, that won’t work but this will.

myHandleTheData's setSomeProp_("say hello")

I am currently working on a video for using multiple scripts in a project.

Right!

Just one of those nights. That was the first thing I tried and it didn’t work. Now it does.

Looking forward to the video.

rob