Open Menu
Close Menu
Apple
Shopping Bag
Apple
Mac
iPad
iPhone
Watch
TV
Music
Support
Search apple.com
Shopping Bag
Lists
Open Menu
Close Menu
Terms and Conditions
Lists hosted on this site
Email the Postmaster
Tips for posting to public mailing lists
Finding the focused UI element
[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
][
Date Index
][
Thread Index
]
Finding the focused UI element
Subject
:
Finding the focused UI element
From: Arjen Baarsma <
email@hidden
>
Date: Thu, 17 Jul 2008 04:26:22 +0200
Hello everyone,
I've only just started looking into applescript, but I've already been able to make a few tiny scripts that are making my life easier as we speak.
One script that I've been wanting to make for quite some time, but which I don't seem to be able to get to work well is one that brings up a context menu for the control that currently has keyboard focus. The idea is that I'll set up a keyboard shortcut to run this script (using quicksilver), so I'll be able to access context menus without touching the mouse (like one could do on a Windows machine using the context menu key, or like what happens when you press ctrl-space when a control/link is selected in firefox in OS X).
Once I have found the UI element that has keyboard focus, bringing up the context menu is no problem (using "AXShowMenu", although it doesn't work for all controls, but I'll worry about that later), so the main problem right now is finding the focused UI element. The most straighforward way to do this I could think of was
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.
I've also written a function that parses all UI elements in a window (and their children and children's children etc) until it finds the one that has focus, but when there are many of them (which happens quite often) it becomes VERY slow (can take minutes or even longer), so that's not going to work either.
I suspect there should be an easy solution, but I'm completely out of ideas. Searching for it on the net hasn't yielded any results (not for just applescript at least), so if anyone knows how to do this, I would be very grateful.
– Arjen
p.s. I'm running OS X version 10.4.11 (and AppleScript 1.10.7), should that be relevant. _______________________________________________
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
Follow-Ups
:
Re: Finding the focused UI element
From:
Bill Cheeseman <email@hidden>
Re: Finding the focused UI element
From:
Philip Aker <email@hidden>
Prev by Date:
Re: UI scripting question
Next by Date:
Re: Finding the focused UI element
Previous by thread:
Re: UI scripting question
Next by thread:
Re: Finding the focused UI element
Index(es):
Date
Thread