I need to store the focused/active window item when entering in another.
ie: get the active text fied of a window before the user clics a button to change the value of text fied.
(if you can understand what I said, you’re a genius :lol:)
I would have recommended using the first responder, but according to Apple…
I tried a few test runs anyways and got no return reading the value of the first responder.
You could use a creative combination of setting and reading values attached creatively to events, but it might get complicated if you had a really complex page with lots of text fields and other objects. I used something like this, and it seemed to work OK…
property thePreviousObject : ""
on action theObject
(* Set the current value to the name of the focused object *)
set thePreviousObject to (name of theObject) as string
(* Test text field to show what the current value is *)
set contents of text field "PreviousObject" of window "window" to thePreviousObject
end action
This was attached to all of the text fields in the window and set the variable to the name of whatever the last text field touched was. It sets it as soon as the object becomes focused, and works with both clicking in the field and tabbing to the field as the focus method.
You can easily reference the text field with something like…
on clicked theObject
set contents of text field theCurrentObject of window "window" to "This was the previous Object"
end clicked
You could add an “on end editing” handler to the text fields and identify them that way but I have found that this severely degrades the UI performance, especially on pre-10.3 machines.