views:

184

answers:

2

I'm using the Cocoa Accessibility API to try and modify the value of a text field (AXTextField) in another application, but I've run into a problem: my code correctly identifies and modifies the contents of the text field in question, and the text of the field visibly changes, but the changes aren't registered by the program I'm trying to control. Is there a way to do this in with the API without having to generate keyboard events?

Sample code:

AXUIElementCopyElementAtPosition(appRef,
    clickPoint.x,
    clickPoint.y,
    &boxRef);

NSString *valueToSet = [NSString stringWithFormat:@"%f",amount];
AXUIElementSetAttributeValue(boxRef,kAXValueAttribute,valueToSet);

And the text field changes to the value specified in "amount" but the other program doesn't recognize the change - I have to go type the number in myself to get it to pick up the change (I can tell the difference, because the program responds when a new value is typed in the box). Can anyone point me in the right direction?

+1  A: 

For posterity: Informed sources tell me that this is actually a bug in the application I'm trying to control. You can tell the difference by using UI Browser (http://prefabsoftware.com/uibrowser/) to try and set the value of the textfield; if UI Browser can't make the change stick, then the matter is out of your control.

A: 

Try telling the text field: perform action "AXConfirm"

This is Applescript, but whatever the Cocoa equivalent is, it may make the change stick even if UI Browser can not (I've used it before).