Why doesn't this work? (XCode & Applescript problem)

I am new to Applescript and XCode so please be patient :slight_smile:

I have created an Applescript Application, and edited the mainmenu.nib to include an NSTextField (called field1) and a button (called theButton). Here is the code I have written in the Applescript:

on clicked theButton
	display dialog (content of field1) as text
end clicked

When I press the button I get an error that the variable field1 is not defined. However, if I create an “on changed field1” clause and tell it to display the contents of field1 then it works.

If the AppleScript name of the text field in IB is “field1” then change the line to:

contents of text field “field1”

Incorrect references to objects is, for me, one of the easiest mistakes to make. You should always check these carefully.

Hi Joseph

Thanks for your quick response. I changed the line to “display dialog (contents of text field “field1”) as string” and got the following error:

Can’t make «class conT» of «class texF» “field1” of «script» into type string. (-1700)

Just sorted it actually:

set xmlFile to contents of window "mainwindow"'s text field "xmlFile"

Oh yeah; the window. See what I mean. :wink:

The alternative is:

contents of text field “xmlFile” of window “mainwindow”

I have to say, I hate this way of referring to objects. My previous platform was Delphi on Windows and the dot-separated method of object referral looked much cleaner and was easier on the eye IMO. For example:

tab view item “config” of tab view “tabs” of window “mainwindow”
in AppleScript under XCode

in Pascal under Delphi.

I still wish Borland would port Delphi to MacOS…