Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How can I detect when a text field changes in Cocoa-Applescript?

I'm working on an application where I have one text field, and below it, a "Send" button. When the button is pressed, is sends whatever is typed in the field to all the user's Skype contacts. I have to prevent the user from sending a blank message to all contacts, so I have to change the button's setEnabled. I've been using an NSTimer to check every second, which works, but it lags my application hugely. Is there any handler that is run whenever text is added or deleted? Perhaps something like:


on myTextFieldDidChange_(aNotification)

Posted on Sep 19, 2013 4:30 AM

Reply
Question marked as Best reply

Posted on Sep 19, 2013 4:54 AM

Why not just check the text field in the method that is called when the send button is pressed and if the field is blank just ignore it?

10 replies

Sep 19, 2013 8:01 AM in response to Apple_For_The_Win

red_menace answered your actual question however in your first post this is what you wrote:


I have to prevent the user from sending a blank message to all contacts, so I have to change the button's setEnabled.


preventing a blank message from going out can be done by checking the text field once the users presses return or the send button and is a lot more efficient then checking for each typed char.


You'll get better responses to your questions and save everyone's time if you can actually ask the question that you want answered and supply all the relevant information up-front.



And could you do us all a favor and trim the tags you add to tour posts. Makes it a pain when reading here on a mobile device.

Sep 19, 2013 8:06 AM in response to Apple_For_The_Win

A specific text field is not used in the handler call - the delegate method is called for all text fields. In the case where you have several text fields, you can get the notification's object, for example:


oncontrolTextDidChange_(aNotification) -- a text field changed, so check it out


setthisTextFieldtoaNotification's object() -- the current control being changed


settheTexttothisTextField's stringValue()


logtheText


-- whatever

endcontrolTextDidChange_

Note that you need to connect the text field's delegate outlet to your AppDelegate (or whatever class you are using for the delegate).

Oct 1, 2015 8:58 AM in response to ManManInfo

You should start a new topic with your particular problem, since the specific details in your situation would be different and your reply doesn't add to solving the OP's (solved) problem.


With that said, the "unrecognised selector" error message usually means that the message (handler call) sent to an object can't be found, which could be a result of misspelling (including capitalization, since Cocoa methods are case sensitive) or a wrong or missing object (e.g. trying to use a textField method on a button, or trying to use a method on an object that hasn't been created).

How can I detect when a text field changes in Cocoa-Applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.