Re: Setting the focused UI element from AppleScript?
Re: Setting the focused UI element from AppleScript?
- Subject: Re: Setting the focused UI element from AppleScript?
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 28 Oct 2006 06:39:17 -0400
- Thread-topic: Setting the focused UI element from AppleScript?
on 2006-10-27 6:46 PM, Timothy J. Wood at email@hidden wrote:
> I'm working on some AppleScript-driven automated tests and it would
> be very useful to use GUI scripting to change focus in the application
> (followed shortly by keyboard events to simulate user events). I
> don't see a way to set the focused element, though.
>
> The 'focused' property on UI element is specified r/w, but setting
> it is generating a scripting error for me. Is this supposed to work?
> Is there a different way, or should I hack something in myself (along
> with a Radar? :)
GUI Scripting questions are more usually handled on the applescript-users
list, but here are some suggestions:
Some UI elements have an AXFocused attribute, such as windows and text
fields; others do not. Those that do sometimes consider the AXFocused
attribute settable, such as Finder windows and their search text fields;
others do not, such as TextEdit windows. Some UI elements claim that their
AXFocused attribute is settable when it really isn't.
Technically, you should only be able to set the AXFocused attribute to true.
Doing that will automatically set the previous key UI element's AXFocused
attribute to false.
I haven't actually tested out whether setting a settable AXFocused attribute
to true causes keystrokes to be sent to that UI element, but it would be
easy enough to test. You would use GUI Scripting statements like this in
your test script:
set focused of text field 3 to true
Or:
set value of attribute "AXFocused" of text field 3 to true
And something like this, addressed not to a UI element but to the
application process itself (which would automatically direct it to the
current key UI element):
keystroke "x is key"
Also, take a look at the Processes Suite of the System Events application's
dictionary. GUI Scripting implements a 'select' verb. I have had spotty
success with 'select' but it may work for you.
select button 3 of window "My Window Title"
Be sure to check out the accessibility actions that may be supported by the
UI element you want to target.
click button 3 of window "My Window Title"
Or
perform action "AXPress" of window "My Window Title"
When all else fails, try GUI Scripting's 'click at' verb. Versions of PreFab
UI Browser prior to 2.0 (which isn't quite ready for release) generate an
invalid script for 'click at'. Here is the correct syntax:
try
tell button 3 of window "My Window Title"
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
end try
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden