Re: GUI scripting menu item with leading spaces
Re: GUI scripting menu item with leading spaces
- Subject: Re: GUI scripting menu item with leading spaces
- From: deivy petrescu <email@hidden>
- Date: Thu, 10 May 2007 18:32:42 -0400
On May 10, 2007, at 17:34, Jim Clause wrote:
Does any one have an idea on how to use GUI scripting to click a menu
item with a leading space. I'm trying to access the Open Recent menu
of Preview but my script is failing. Other nested menus, like the
Finder's View -> Arrange By -> Name work fine.
I'm tried writing my own script and using the so_submenu script from
http://www.apple.com/applescript/uiscripting/03.html both fail.
Here's my attempt that fails:
tell application "Preview" to activate
tell application "System Events" to click menu item "bug.jpg" of menu
1 of menu item "Open Recent" of menu 1 of menu bar item "File" of menu
bar 1 of application process "Preview"
However if I change the reference for the menu item from menu item "
bug.jpg" to menu item 1 everything works. Unfortunately since the
Open Recent menu gets rearranged I can't rely on the items being in
the same place.
Thanks,
~Jim
You are right Jim.
The problem is that the space before the name is not just a space,
it contains some other characters.
To overcome this problem I suggest the following (which works here)
but might be problematic in a general situation.
<script>
tell application "Preview" to activate
tell application "System Events"
tell menu item "Open Recent" of menu 1 of menu bar item "File" of
menu bar 1 of application process "Preview" to set nl to name of
every menu item of menu 1
repeat with l in nl
set lc to contents of l
if lc contains "bug.jpg" then exit repeat
end repeat
tell menu item lc of menu 1 of menu item "Open Recent" of menu 1 of
menu bar item "File" of menu bar 1 of application process "Preview"
to click
end tell
</script>
Deivy
_______________________________________________
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