I have a Controller script and other applescript classes within a project.
In the classes I handle different tasks and functions within a class can call others in other classes.
These tasks need to access the current values of different fields, buttons etc. defined in a GUI.
For many of these elements i am using bindings.
How can I use the value of these bindings in the other classes. (ask the values when needed).
If you have a property in a class, let’s say called someProperty, you can get its value from another script by calling someProperty() on it. To access that other script, you need to make sure both are instantiated in Interface Builder, then make an outlet in the calling script that is connected to the target script. Then you call the handler on the new property:
Hi Shane
I have tried to do what you suggest, but it doesn’t seem to work for me (i am sure i am doing it wrong.)
I will try to expalin:
in The interface I have a text field and a button.
I have a contoller script:
script Controller
property parent : class “NSObject”
property someProperty : “----” – binding of text field to Controller
end script
and a script class :
script myClass
property parent : class “NSObject”
property callerScriptOutlet : missing value – connected from myClass to Controller
on getTextFieldValue_(sender)
tell me to log current application's Controller's someProperty()
end getTextFieldValue_
end script
In interface builder I added two objects en assigned them the class they belong to.
When i run i get the following error:
-[myClass getTextFieldValue:]: +[Controller someProperty]: unrecognized selector sent to class 0x20057ee00 (error -10000)
script Controller
property parent : class "NSObject"
property myTextField :missing value-- binding of text field to Controller
on myTextFieldStringValue()
return (myTextField's stringValue())
end myTextFieldStringValue_
on myTextFieldFloatValue()
return (myTextField's floatValue())
end myTextFieldFloatValue_
end script
and then:
script myClass
property parent : class "NSObject"
property Controller : missing value -- connected from myClass to Controller
on getTextFieldValue_(sender)
set myString to Controller's myTextFieldStringValue() as string
set myReal to Controller's myTextFieldFloatValue() as real
log "String returned: " & myString & " Real returned: " & myReal
end getTextFieldValue_
end script
Note the + sign in there: you’re trying to call it as a class method, by addressing it to the class, when you really want to call it as an instance method, addressing it to your instance.
script myClass
property parent : class “NSObject”
property callerScriptOutlet : missing value – connected from myClass to Controller
on getTextFieldValue_(sender)
log callerScriptOutlet's someProperty()
end getTextFieldValue_
Shane’s solution works just fine. I indeed noticed the + sign for the class, but did not know how to call the instance instead.
I will try the other solution too for testing puposes.