AppleScript:终端中的“系统事件”不起作用

问题描述 投票:0回答:1

任务: 我正在使用 AppleScript 打开 Numbers 文件并隐藏一列。选择要隐藏的列后,我使用“系统事件”进入“数字”菜单并隐藏该列。

问题: 当我从 AS 编辑器启动脚本时,脚本可以工作,但是当我使用 osascript 从终端启动相同的脚本时,脚本的“系统事件”部分不起作用(该列被选中但没有隐藏)。

我尝试过的: 在“设置”->“隐私和安全”->“自动化”中:终端应用程序同时启用了数字和系统事件 在设置 -> 隐私和安全 -> 辅助功能中:终端应用程序已启用。

这是代码(系统事件部分)

tell application "System Events"
    tell process "Numbers"
        click menu item "Hide Column" of menu 1 of menu bar item "Table" of menu bar 1
    end tell
end tell
macos terminal numbers applescript accessibility
1个回答
0
投票

我的“系统事件”调用被“忽略应用程序响应 - 结束忽略”所包围。

实际代码是:

ignoring application responses
    tell application "System Events"
        tell process "Numbers"
            click menu item "Hide Column" of menu 1 of menu bar item "Table" of menu bar 1
        end tell
    end tell
end ignoring

“忽略”中的部分实际上在通过终端运行代码时被忽略,而如果通过脚本编辑器运行则有效。

© www.soinside.com 2019 - 2024. All rights reserved.