setting a variable to contents of a text field

this is really weird, but ive been using this to set the text of a field to a variable using:

tell window "mainwindow"
                         set thevar to contents of textfield "thetext"
                  end tell

when i use it, i get an NSReceiverEvaluationScript Error. help?

A text field object is two words, not one (i.e., “text field” not “textfield”).

Jon

sorry, i didnt cut and paste it, in the code its really “text field”

Then something along your reference chain is not named like you think it is, or, your text field is contained by some object (like a box or a tab view item of a tab view) that you have not included in your reference.

Jon

you need to add “of window 1” or whatever window it is from.

Hi,

No, you don’t need to add another reference to “window 1” or whatever, as suggested by viscousfishes since is is already inside a tell window block.

Jon is right, there must be something amiss in your naming and until you find it, you will not be able to get to the content of that text field of yours.

Check your main window and make sure it is named “mainwindow”. That and the name of your text field.

Seek and ye shall find.!

archseed :slight_smile:

Sorry about the window thing!

A problem I kept having was trying to get the text from a “NS Text View” instead of a text field, it needs to be referenced properly if it is a text view. Check in your interface builder, select it and in the Inspector panel look at custom class. Good luck!