Soy bastante nuevo en applescript (y un programador principiante) y me han llegado a un callejón sin salida. Me di cuenta de cómo acceder a un elemento de menú de un proceso, pero no sé cómo hacerlo una vez que tengo varias ventanas. Gracias por cualquier ayuda que se le puede dar!
antecedentes: Estoy tratando de utilizar Applescript con Fiji Es Sólo ImageJ (FIJI) para el proceso de un par de cientos de archivos de imagen en un momento. Necesito usar el "Plugins>Segmentación>Simple de las Neuritas Trazador" plugin, pero no funciona bien con FIJI nativos del lenguaje de macros, así que estoy tratando de applescript.
Lo que he intentado: Ya he configurado algo que el bucle a través de las imágenes una por una y almuerzo el plugin, pero después de que yo no puedo averiguar cómo acceder a los nuevos menús de las ventanas que se abren.
tell application "Fiji" to activate
delay 3
menu_click({"Fiji", "Image", "Type", "8-bit"})
-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- 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, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) 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 f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
He utilizado la accesibilidad inspector para intentar averiguar los nombres de las ventanas de manera que se puede utilizar el mismo proceso que hice para lanzar el plugin, pero yo no era capaz de comprenderlo. El nombre de la ventana en sí es predecible, así que puede tomar el nombre del archivo que quiero abrir y añadir "la búsqueda para:" antes de él.
Yo estaba en otra página, que era similar, pero no podía adaptarse, ya sea con tristeza - no hay ningún botón, pero aún clic en un elemento de menú en una ventana en lugar de un proceso: ¿Cómo hago clic en un botón usando AppleScript?
activate application "Fiji"
tell application "System Events" to tell process "Fiji"
click menu item "Quit" of menu "File" of menu bar 1 of window 1
--click button "Quit" of window 1 of window 1
end tell
Luego traté de usar MouseTools pero no parece funcionar de forma coherente. El primer ratón haga clic en los registros de la perfección, pero el segundo a veces funciona y a veces no.
-- move the mouse to the x/y coordinates (as measured from the top-left part of the screen) and perform a mouse left-click
set mouseToolsPath to (path to home folder as text) & "MouseTools"
set x to 60
set y to 44
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text) & " -doubleLeftClick"
set x to 219
set y to 598
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text) & " -doubleLeftClick"