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 mm to value of attribute "AXFocusedUIElement" of p if mm is missing value then error "Current menu missing" if role of mm is not "AXMenu" or name of mm is not "More options" then error "Wrong current owned menu" set ds to menu items of mm whose name is "Duplicate" set rs to menu items of mm whose name is "Rename" if (count ds) is not 1 or (count rs) is not 1 then error "Current menu actions ambiguous" if enabled of item 1 of ds is not true or enabled of item 1 of rs is not true then error "Owned menu actions disabled" if (current application's NSWorkspace's sharedWorkspace()'s frontmostApplication()'s processIdentifier() as integer) is not 9974 then error "Owned foreground changed" if (value of attribute "AXFocusedUIElement" of p) is not mm then error "Current menu focus changed" click item 1 of ds log "NEW_STOCK_DUPLICATE_CLICK_DISPATCHED" return "New stock current-menu Duplicate clicked exactly once; no popup or question" end tell