Posted By

lildemon on 09/13/09


Tagged

menu terminal clickmenu


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tmbrenneke


click menu function


 / Published in: AppleScript
 

  1. on menu_click(mList)
  2. local appName, topMenu, r
  3.  
  4. -- Validate our input
  5. if mList's length < 3 then error "Menu list is not long enough"
  6.  
  7. -- Set these variables for clarity and brevity later on
  8. set {appName, topMenu} to (items 1 through 2 of mList)
  9. set r to (items 3 through (mList's length) of mList)
  10.  
  11. -- This overly-long line calls the menu_recurse function with
  12. -- two arguments: r, and a reference to the top-level menu
  13. tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
  14. (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
  15. end menu_click
  16.  
  17.  
  18. on menu_click_recurse(mList, parentObject)
  19. local f, r
  20.  
  21. -- `f` = first item, `r` = rest of items
  22. set f to item 1 of mList
  23. if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
  24.  
  25. -- either actually click the menu item, or recurse again
  26. tell application "System Events"
  27. if mList's length is 1 then
  28. click parentObject's menu item f
  29. else
  30. my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
  31. end if
  32. end tell
  33. end menu_click_recurse
  34.  
  35.  
  36. on run {input, parameters}
  37.  
  38. tell application "Terminal" to activate
  39. menu_click({"Terminal", "Shell", "New Window", "Pro"})
  40.  
  41. end run

Report this snippet  

You need to login to post a comment.