I have a script for OS X 10.5 that focuses the search field on the Help menu of any application. I have a keyboard shortcut and, like Spotlight, I want it to switch when I run the script. Thus, I want to determine if the search box is already focused for input, and if so, enter Esc instead of clicking on the help menu.
Here is the script as of now:
tell application "System Events" tell (first process whose frontmost is true) set helpMenuItem to menu bar item "Help" of menu bar 1 click helpMenuItem end tell end tell
And I am thinking of something like this:
tell application "System Events" tell (first process whose frontmost is true) set helpMenuItem to menu bar item "Help" of menu bar 1 set searchBox to menu item 1 of menu of helpMenuItem if (searchBox focused) = true then key code 53
... but I get this error:
It is impossible to concentrate on {menu 1 of the "Help" menu item of the "Help" menu item of the menu bar 1 of the "Script Editor" application process of the "System Events" application}.
So, is there a way to make my script detect that the search box is already focused?
I solved my problem by working around her . I still don't know how to check if a menu item is selected, so I will leave this section open.
Kevin conner
source share