AppleScript:如何激活仅使用向下选项键出现的菜单项(w/o 快捷方式)

AppleScript: How to activate menu items that only appear with option-down key (w/o shortcut)

我确实在此处和 "AskDifferent" 上查了很多问题,但找不到这个基本问题的有效答案:

您如何 "activate" 以编程方式创建一个仅在按下选项键时可见且没有自己的快捷方式的菜单项?
我知道如何使用:

click menu item "Save as …" ...  [or:]  perform action of menu item "..." ...

...很好。
我还了解了以前设置的命令,例如:

key down option    [or:]  keystroke "whatever" using option down

但是 none 其中 将执行对菜单项的简单单击 "regularly" 不可见


承认,使用像 "option shift command s" 这样的现有快捷方式将按预期 "Save as …":

keystroke "s" using {option down, shift down, command down}



(再往下看,我被 pbell 证明是错误的;所以这是我最新的 "simplified" 解决方案:

tell application "System Events" to perform action "AXPress" of menu item ¬
      "Arrange in front" of menu "Window" of menu bar item "Window" of ¬
      menu bar 1 of application process "Script Editor"

(我现在发现,这段代码将做完全相同的事情。)

您必须使用按键和按键指令。下面的脚本可以满足您的需求。它显示脚本编辑器的菜单 Window,选项键按下。

tell application "System Events"
tell process "Script Editor"
    key down option
    click menu bar item 9 of menu bar 1 --using {option down}
    delay 2 -- just to show ! to be replaced by your click on your menu item
    key up option -- don't forget this : if you do, it keeps option down until you force to quit the process !!!
end tell    
end tell

实际上所有菜单项都可以通过系统事件/GUI 脚本访问,即使它们是不可见的。不需要更改修改键。

这段代码就足够了。可以省略使应用程序位于最前面的行,因为即使应用程序不在前台也可以访问菜单项。

tell application "System Events"
    tell process "Script Editor"
        set frontmost to true -- replaces 'activate application "Script Editor"'
        perform action "AXPress" of menu item "Arrange in front" of menu "Window" of menu bar item "Window" of menu bar 1
    end tell
end tell

我会用这个:

activate application "Script Editor"
tell application "System Events"
    tell process "Script Editor"
        click menu item "Arrange in Front" of menu 1 of menu bar item "Window" of menu bar 1
    end tell
end tell

vadian 的方法也是一种可以接受的方法。