Can't seem to change value of a text filed

I know there are a lot of posts here about this but I can’t seem to see how my script is any different then those that are working. Except that mine does not.

I simply want to change a text field to a string of my choosing.

Here’s what I’ve got…

on awake from nib theObject
    tell window "main" to set the contents of text field "owner_name" of box "file_info" to "Some Name" as string
end awake from nib

the error I get is…

NSReceiverEvaluationScriptError: 4(1)

I think what I’ve got is pretty straight forward so I’m very confused.

You don’t need to use tell. Just…

set the contents of text field “owner_name” of box “file_info” of window “main” to “Some Name”

Also, I see that it’s under awake from nib. I think this means when it’s opened. Instead of using AS to set the value just do it in IB. Double click the field and enter in text.


This is the error I get when I try that.

Can't make contents of <<class texF>> "owner_name" of <<calss boxO>> "file_info" into type reference. (-1700)

And my example here is purely for simplicity. Ultimately I want “Some Name” to become a variable which I will change but right now I can’t even get this to work.

The reason I used the tell is because theObject that is awakened is different than the text field object.
I am trying to figure out how to change the text field of one object from AS when called from another object.

have you made sure you have checked off all the appropriate check boxes in IB. The main window, and box should be checked (connected to your script) and the text field should not.

Well, I had not connected the box to the script so I feel you may be onto something, however I still get a

NSReceiverEvaluationScriptError: 4 (1)

Hi tdog,

your and HarryCaray’s script lines both look correct and should work. I suspect there’s something wrong in your addressing of this text field. Maybe the box is a subview of a further view - a tab view maybe - or there is a typo in one of the names?
You can easily find out if there’s an additional view in the path, when you connect your text field to (for example) the ‘mouse entered’ handler in Interface Builder and adding a ‘log theObject’ in this handler:

on mouse entered theObject event theEvent
	log theObject
end mouse entered

Then the ‘path’ to this text field is logged on mouse over in your project’s Run Log window when you run your project from xCode.

Hope that helps …


Hey that’s a great little trick. Thank you. Armed with that information I discovered that the text field was not actually a child of the box it sits in. More to learn there I suppose.

Also I had to change the “contents” to “string value” so in the end it became:

set the string value of text field "owner_name" of window "main" to "Some Name"

instead of

tell window "main" to set the contents of text field "owner_name" of box "file_info" to "Some Name" as string

Thank you very much.