textDidChange:

hello,

I have a problem using text did change: I can’t get NSNotification center to tell my script a text field was changed.
I already have this subroutine:

  on controlTextDidChange_(aNotification)
        set theObject to aNotification's object
        if theObject = SerialKey then
        set SerialkeyValue to SerialKey's stringValue
            display dialog SerialkeyValue
            end
        end controlTextDidChange_

I also added the property and NSNotificationCenter’s defaultCenter()'s addObserver_(“textDidChange:”) to applicationwillfinishlauching.

But i’m still getting nothing from NSNotification center.

I can say that I only used notification center only once before and only got it to work with really much help from DJ Wazzie Bazzie.

If you need the entire script, please say so.

Thanks!

Hello,
I’ve always received the notifications using the same routine as yours:

on controlTextDidChange_(aNotification)

if, and only if, the textField has the main script set as its delegate (in IB).

Regards,

You don’t need to (and shouldn’t). Instead, make sure your script instance is the delegate of the relevant text field.

Xpresso,

If you are unsure about delegates --and delegate protocols-- , there is a good video on Shane Stanley’s site, “demonstrating the connection of application interface elements to their corresponding AppleScript function code using Interface Builder outlets and actions”.

The address is http://www.macosxautomation.com/applescript/apps/explorer.html

Regards,

thank you all for responding so fast! since i’m on my phone right now, ill look into your answers tonight.

How should i link the textfield to the delgate?

I linked the oulet delgate to the app delegate.
But still no luck. I can’t get it to work

can anyone make a small example?

thanks!

Well, I don’t know how to post screen shots, so:

In IB, you click on your text field to get it selected, then, maintaining the CTRL key pressed, you drag your text field to the app delegate blue cube, and in the hub window which appears, you choose “delegate”.

This makes your main script the delegate of the text field, and from now the notifications sent by the text field will be received by your main script – that is, your controlTextDidChange_ handler will be called.

Not evident at the beginning, but you will certainly master it and then use and abuse from the binding mechanism :wink:

Regards,