Access global/property from within panel

Dear intelligent people,

I am writing a small AS studio program in which I want to use a panel window or sheet.
In that panel I use a button, which has to work with a global variable from the main window and script.
The button’s applescript scope is set to the main script.

When I click the button though, it always shows me the default value of the property and not the one into which it has already been changed by actions in the main script. When I add a similar button to the main window, this does show the right updated version…

I will add some demo code, just have to make a cleaned example, but if someone already understands my problem and thinks to have a solution, feel welcome to post it here!

Thanks in advance,


Edit: the demo code / removed all non-necessary stuff:

property myPath : (path to me)
property panelWIndow : missing value
property theDoubles : 3
property curConflictNr : null

on clicked theObject
	if the name of theObject is "testBTN" then
	else if the name of theObject is "testBTN2" then
	else if name of theObject is "useGbtn" then
	end if
end clicked

on panel ended thePanel with result theResult

end panel ended

on duplicateOpenPanel()
	global curConflictNr

	set myPath to (path to me as string)
	set shellphp to POSIX path of file (myPath)
	set theDoubles to do shell script ("php " & shellphp & "Contents/Resources/test.php")
	display dialog theDoubles
	if (theDoubles is "0") then

		set curConflictNr to 1
		if panelWIndow is equal to missing value then
			set panelWIndow to window "duplicates"
		end if
		-- display panel panelWIndow attached to window "main" -- commented out in a try to see if it differed, no changes in results
		display panelWIndow
		tell panelWIndow
			set content of text field "conflictStatus" to "Conflict " & curConflictNr & " of " & (count paragraphs of theDoubles)
		end tell
	end if
end duplicateOpenPanel

on testShowDoubles()
	display dialog (theDoubles)
end testShowDoubles

The setup:

  • Main window
    ±- button “testBTN”
    ±- button “testBTN2”
  • “Duplicates” NSPanel (in same nib, was in separate nib before, same results)
    ±- button “useGbtn”

when I click the testBTN2, it will show the correct contents of theDoubles (tab-separated text)
when I click the useGbtn, it will show the default value of the propery (3)
if I make the default propery null, then it will show some number, always the same, looking like a epoch timestamp.

Just as an update: I tried to use a window instead of a panel, in the idea that it might be less beautiful but at least work, only to see that it gives the same results: trying to use a property from the main script just returns its “default” value. When I try to use a global instead of a property, then the button in the secondary window results in a “unspecified variable” error.

Any help would be really welcome!

OK, I found the solution in this mailing list post:

The mistake was that the buttons which open the panel and load the values into the property had a scope of “nib” instead of “global”. Changing those solved the problem. Hope this can help others.