Hey Ali,
What app are you working with?
Set the keyboard shortcuts for UI Browser, so you can place the cursor over what you want to read and hit the appropriate keyboard shortcut.
Open the Script Editor.app and place the cursor in the empty script.
Activate your keyboard shortcut in your app as needed.
When UI Browser comes up hit Cmd-Opt-R.
You should then have a reference to the item in your script.
I never use these one-liner references, because they are terribly hard to read – AND I always find myself needing to discover or do something else in the hierarchy.
tell application "System Events"
tell application process "Safari"
tell (first window whose subrole is "AXStandardWindow")
tell toolbar 1
tell group 2
{¬
properties, ¬
UI elements, ¬
attributes, ¬
actions, ¬
null}
end tell
end tell
end tell
end tell
end tell
You never want to use a named window, UNLESS there’s a good reason.
This usually works for normal windows:
tell (first window whose subrole is "AXStandardWindow")
I use this construct to discover information at the given level of the hierarchy.
{¬
properties, ¬
UI elements, ¬
attributes, ¬
actions, ¬
null}
** The null is just a marker, so I can see where my query ends in the result.
Working with System Events and GUI-Scripting tends to be terribly confusing when you start doing it, but the UI Browser, experience, and some mentoring makes it a lot less painful.
-Chris