use framework "AppKit" use scripting additions tell application "System Events" set p to first application process whose unix id is 9974 set w to item 1 of (windows of p whose name is "LM Studio") if value of attribute "AXMinimized" of w then error "Owned window minimized" perform action "AXRaise" of w set frontmost of p to true set untilAt to (current date) + 3 repeat while (current date) < untilAt if (current application's NSWorkspace's sharedWorkspace()'s frontmostApplication()'s processIdentifier() as integer) is 9974 then exit repeat delay 0.05 end repeat if (current application's NSWorkspace's sharedWorkspace()'s frontmostApplication()'s processIdentifier() as integer) is not 9974 then error "Actual owned foreground missing" set menusFound to {} repeat with e in entire contents of w try if role of e is "AXMenu" and name of e is "More options" then set end of menusFound to contents of e end try end repeat if (count menusFound) is not 1 then error "Exact owned More menu not unique" key code 53 log "NEUTRAL_ESCAPE_DISPATCHED" return "Owned exact More menu dismissed by one neutral Escape" end tell