Re: Contextual Menu items using System Events
Re: Contextual Menu items using System Events
- Subject: Re: Contextual Menu items using System Events
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 24 Feb 2006 15:44:51 -0500
- Thread-topic: Contextual Menu items using System Events
on 2006-02-24 1:38 PM, John R. at email@hidden wrote:
> How do I get System Events to select an item on a contextual menu?
>
> UI Element Inspector showed me the AXShowMenu action to get the menu for an
> Image UI Element in Mail. The result is a new "Menu" item in the Text Area,
> according to UI Element Inspector. But I can't see it with my script, so I
> can't press any of it's Menu Items.
>
> Am I doing something wrong?
>
> - John R
>
> tell application "Mail" to activate
> tell application "System Events" to tell process "Mail"
> tell window 1
> tell scroll area 1
> tell text area 1
> tell image 1
> perform action "AXShowMenu" --> Menu comes up fine.
> end tell
> delay 3 --> Just in case it's a timing thing.
> return menus --> None, even though UI Element Inspector sees it.
> end tell
> end tell
> end tell
> end tell
I can't reproduce your experience because my scroll area 1 doesn't have a
text area 1. You'd have to explain what manipulations you made in Mail to
get a text area into scroll area 1, and an image into the text area.
But, on general principles, you seem to have the nesting of tell blocks
wrong. You perform action "AXShowMenu" on image 1, but then you close that
tell block and try to get the menus of text area 1, which doesn't seem
right. Perhaps what you need to do after getting the menu to show is --
still in the 'tell image 1' tell block -- tell the image to return its
menus.
It's hard to use UI Element Inspector to track these hierarchies, although
it can be done. One good alternative is to run a 'get properties' statement
at each potentially interesting level of tell blocks, to see if the menu
you're look for turns up. An even better alternative is to buy PreFab UI
Browser, at <http://www.prefab.com/uibrowser/>. We let you use it for free
for 30 days without restriction, which is usually more than enough time to
solve a problem like this without having to pay us anything. A hint for
solving this problem with UI Browser: check out our Hot Keys feature. Open
the contextual menu you're interested in in Mail, put the mouse cursor over
it, then press the UI Browser system-wide hot key. UI Browser should
immediately show you the exact hierarchy to the menu or even the menu item
you're interested in.
Also, there are two things to remember about menus. (1) The hierarchy is
menu > menu item > menu > menu item and so on. (2) The top-level menu of
disconnected menus, such as contextual menus and certain others, always have
a weird name that you can't normally see, but they almost always have an
index of 1, so you can refer to them as 'menu 1'.
--
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.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden