Friday, July 21, 2017

#1 2016-07-21 10:04:49 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Accessing Properties

I have come back to AppleScriptObjc after a few years absence and need a little help.

If I have a script

Applescript:


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

Offline

 

#2 2016-07-21 09:18:16 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5046

Re: Accessing Properties

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2016-07-22 08:40:55 am

tellboy
Member
Registered: 2005-06-23
Posts: 152

Re: Accessing Properties

Can't seem to get the two controllers to link so have settled on a GlobalController:

Applescript:


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:

Applescript:



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

Offline

 

#4 2016-07-28 11:16:28 am

Jonathan Engelhardt
Member
Registered: 2010-06-11
Posts: 57

Re: Accessing Properties

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


Applescript:

script lib
property parent : class "NSObject"

property globalController: missing value
property anyOtherScript: missing value

end script

In your GLobalController Script add

Applescript:


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.

Applescript:

lib's globalController's getAccountsOpen()
lib's globalController's someProperty

Last edited by Jonathan Engelhardt (2016-07-28 11:18:08 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)