START > APPLESCRIPT > Praktische Handler > UIScripting Menü-Klick

UIScripting Menü-Klick

Ein Applescript-Handler, um einen Menüpunkt in einem x-beliebigem Programm zu klicken. Ein genialer (rekursiver) Handler, der es erlaubt, Submenüs einfach per UIScripting zu aktivieren.

Vielen Dank unbekannterweise an «jacobolus» (macosxhints), abgelutscht aus diesem Thread.

(Hier habe ich das Original-Posting des Autors ausfindig machen können, in dem auch noch weitere Erklärungen zu finden sind).

Ein toller Handler, der einem eine Menü-Auswahl wirklich erleichtert.

-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--    method "menu_click" (recursiv) provided by jacobolus (macosxhints)
-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

-- ____BEISPIEL-AUFRUF {app, menubar, menu ... , submenu, ...}____
tell application "iTunes" to activate
set input to {"iTunes", "Darstellung", "Visuell", "Optionen…"}
menu_click(input)
-- _____________________________________________________
on menu_click(mList)
   local appName, car, cdr
   
   -- Validate our input
   if mList's length < 3 then error "Menu list is not long enough"
   
   -- Set these variables for clarity and brevity later on
   set {appName, car} to (items 1 thru 2 of mList)
   set cdr to (items 3 thru end of mList)
   
   -- This overly-long line calls the menu_recurse function with
   -- two arguments: cdr, and a reference to the top-level menu
   tell application "System Events"
      my menu_click_recurse(cdr, ((process appName)'s (menu bar 1)'s (menu bar item car)'s (menu car)))
   end tell
end menu_click

on menu_click_recurse(mList, parentObject)
   local car, cdr
   
   -- 'car'= first item, 'cdr'= rest of items
   set car to item 1 of mList
   if mList's length > 1 then set cdr to (items 2 thru end of mList)
   
   -- either actually click the menu item, or recurse again
   tell application "System Events"
      if mList's length is 1 then
         click parentObject's menu item car
      else
         my menu_click_recurse(cdr, (parentObject's (menu item car)'s (menu car)))
      end if
   end tell
end menu_click_recurse

 Im Scripteditor öffnen
Kommentar schreiben



Powered By CMSimple Design By NMuD Top