I have come back to AppleScriptObjc after a few years absence and need a little help.
If I have a script
script MenuController
property parent : class "NSObject"
--General Properties
property pAccountsOpen :false
property pFMDBase : missing value
-- IBOutlets
property theWindow : missing value
property pTabView : missing value
...
end MenuController
How do I access pAccountsOpen from another script in another file.
Thanks
Terry
You need the two to have a connection of some sort; one needs an outlet to the other. if that’s difficult to achieve, you should consider something like storing the property value in defaults, and accessing it that way from both script instances.
Can’t seem to get the two controllers to link so have settled on a GlobalController:
property pAccountsOpen :false
script GlobalController
property parent : class "NSObject"
on getAccountsOpen()
return pAccountsOpen
end getAccountsOpen
on setAccountsOpen_(tFlag)
set pAccountsOpen to tFlag
end setAccountsOpen_
end script
Called by:
set tAccountsOpen to current application's GlobalController's getAccountsOpen() as boolean
current application's GlobalController's setAccountsOpen_(false)
This is the only way I seem to be able to do it.
Any other ideas?
Thanks
Terry
Like Shane said you need to connect them.
Best would be to have one central script to connect everything to instead of haveing cross connections all over
e.g.
create a new script lib.applescript
script lib
property parent : class "NSObject"
property globalController: missing value
property anyOtherScript: missing value
end script
In your GLobalController Script add
script GLobalController
property parent : class "NSObject"
property lib: missing value
...
end script
Then in Interface builder where you get buttons from the library get a blue cube (search for “object”) and add it to the object/views list on the left.
Select it and write in the Custom Class field (right side,third tab from the left) “lib” to connect it to the lib object.
Repeat that with your GlobalController.
So you should have two blue cubes - one for lib, the other one for your globalController.
Select the lib object you just created and go to the bindings inspector (right side, third tab from right). You should see a GlobalController property. Connect it to the GlobalController blue cube by dragging a line from the circle on the right to the blue cube on the left.
Repeat that with the Global Controller cube (connect to lib cube).
Once done you can always access GlobalController from outside by using lib as bridge - just make sure, every script is connected to lib and lib is connected to every script! So you just need to connect every script to lib instead of connecting each with everything.
lib's globalController's getAccountsOpen()
lib's globalController's someProperty