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.
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.