save variable in field

I’m sure this is a FAQ somewhere, but I haven’t found it. I have a simple app that asks for some text, which is entered into a text field, then the user clicks the button. However if the user doesn’t click out of that text field, the data is not saved into the variable. What’s the trick?
thanks, Y

Normally, the user has to push return or tab, or click out of the text field to notify that app that the editing is done – there is a way around this, but whether you want to do that depends on what you are doing with the text that the user enters. You can use the delegate method controlTextDidChange: to see the change in the text – this is called after each character that is entered. You can get the current string this way, but there’s no way to know if the user is done entering the text.

Ric

What you are wanting is force the text field to commit it’s changes. The common way to do this to do the programming equivalent of clicking somewhere else: call makeFirstResponder: on the containing window, passing missing value:

mainWindow's makeFirstResponder_(missing value)

It returns a boolean, and it can be false if, for example, the first responder is a field with a formatter and the value entered is illegal, but otherwise you can just ignore the result.

Thank you team. Shane, your suggestion worked perfectly!