Notification when text field is activated (tab or click)?

Hello,

I have a series of text fields in my interface. A user types a small bit of ‘markup’ script in one of the text boxes and a preview field at the bottom of the screen shows what the result of their script would be. When the user changes text fields, I need the preview box to change to preview the contents of the newly activated text field.

The problem:
I can’t seem to find any way to be notified when a new text field is activated (by clicking or tabbing). Unfortunately, ‘begin editing’ and ‘should beging editing’ only get called when the user types a letter, not when the field is activated.

Did I miss something or am I going to have to check which field is active after every keystroke and mouse click just to figure out when the field has changed?

Thanks,
Colin.

Assuming a bunch of input text fields, and an “output” text field, this code will update the contents of the output field with whatever the contents of the active field is. Attach the ‘on action’ handler to every text field that will be monitored as a potentially “active” field. Replace the changed handler to execute whetever code you’re using to update the output field. This will work for clicking and tabbing. Note that it also is called on every key stroke, so fast typing or slow processors might cause some hanging or other unpredictable results.

property theCurrentObject : missing value

on action theObject
	set theObjectRef to a reference to theObject

	if theObjectRef is not theCurrentObject then
		set theCurrentObject to theObjectRef
	end if
end action

on changed theObject
	set thisOutput to (content of theObject) as string
	set contents of text field "output" of window "window" to thisOutput
end changed

j

Hmmm… that’s what I was afraid of…

[time passes]

Ah hah!

Well, this doesn’t give you notification, but if you want to get the name of the field that currently has focus (the field that is the first responder) then this works:

set current_focus to name of super view of super view of current field editor of window 1 as text

Yes, ‘super view’ must be specified twice.

Well, that helps a little, anyway.
Thanks!
-Colin.