code_junkie

In Applescript, how can I find out if a menu item is selected/focused?

Nov 10th, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. tell application "System Events"
  2. tell (first process whose frontmost is true)
  3. set helpMenuItem to menu bar item "Help" of menu bar 1
  4. click helpMenuItem
  5. end tell
  6. end tell
  7.  
  8. tell application "System Events"
  9. tell (first process whose frontmost is true)
  10. set helpMenuItem to menu bar item "Help" of menu bar 1
  11. set searchBox to menu item 1 of menu of helpMenuItem
  12. if (searchBox's focused) = true then
  13. key code 53 -- type esc
  14. else
  15. click helpMenuItem
  16. end if
  17. end tell
  18. end tell
  19.  
  20. tell application "System Events"
  21. tell (first process whose frontmost is true)
  22. set helpMenuItem to menu bar item "Help" of menu bar 1
  23.  
  24. -- Use reference form to avoid building intermediate object specifiers, which Accessibility apparently isn't good at resolving after the fact.
  25. set searchBox to a reference to menu item 1 of menu of helpMenuItem
  26. set searchField to a reference to text field 1 of searchBox
  27.  
  28. if searchField's focused is true then
  29. key code 53 -- type esc
  30. else
  31. click helpMenuItem
  32. end if
  33. end tell
  34. end tell
  35.  
  36. tell application "Adobe Illustrator"
  37. activate
  38. tell application "System Events"
  39. tell process "Illustrator"
  40. set frontmost to true
  41. set activeMenuItem to enabled of menu item "Unlock All" of menu "Object" of menu bar item "Object" of menu bar 1
  42. if activeMenuItem is true then
  43. tell me to beep 3
  44. else
  45. tell me to beep 2
  46. end if
  47. end tell
  48. end tell
  49. end tell
Add Comment
Please, Sign In to add comment