Re: Finding the focused UI element
Re: Finding the focused UI element
- Subject: Re: Finding the focused UI element
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 17 Jul 2008 13:49:56 -0400
- Thread-topic: Finding the focused UI element
on 2008-07-16 10:26 PM, Arjen Baarsma at email@hidden wrote:
> tell application "System Events"
> set theApplication to first application process whose frontmost is true
> set theControl to value of attribute "AXFocusedUIElement" of
> theApplication
> end tell
>
> but this does not work unfortunately. I know from a UI Browser that
> the attribute AXFocusedUIElement should indeed take the value of the
> focused UI element, so it's a mystery to me why it doesn't work.
How are you running this script? If you're running it in Script Editor,
Script Editor is the frontmost application, and Script Editor returns
'missing value' as the result.
If your script first makes some other application frontmost, it will work.
Try this, for example. First, set up the Text Edit preferences window as a
test target: launch TextEdit, open its Preferences window, and click in the
Width text field to make it the focused UI element in TextEdit. Then run
this script in Script Editor:
activate application "TextEdit"
tell application "System Events"
set theApplication to first application process whose frontmost is true
set theControl to value of attribute "AXFocusedUIElement" of
theApplication
return properties of theControl
end tell
In the Result pane you should see all of the properties of the focused Width
text field, including its value ("75" on my computer).
To use this technique in a real-world situation, where you don't know what
application is frontmost, you might have to run it from a background script
runner or the Script Menu.
Also, not every application will have a focused UI element that has an
associated contextual menu. I'm not sure how you'll test for the existence
of an associated contextual menu, and I'm not sure how you'll open it when
you find it. Contextual menus have a habit of not coming into existence
until you open them with a real Control-click.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden