首页 > 解决方案 > 在 Powerpoint 中使用 AppleScript 选择橡皮擦

问题描述

首先,是我的问题的视频解释。

我是一名教师,正在寻找一种在使用 PowerPoint 进行演示时轻松访问橡皮擦工具的方法。部分遵循本指南,我尝试使用 Automator 在选择橡皮擦时记录我的操作,将其保存为快速操作,然后为操作分配键盘快捷键。

不幸的是,我得到了错误:

操作“Watch Me Do”遇到错误:“Application Powerpoint 未按预期运行”

或者,如果我首先从 Automator 操作复制代码,将其粘贴到运行 AppleScript 文件中,然后设置执行该文件的快捷方式,我会得到:

“运行 AppleScript”操作遇到错误:“操作无法完成。(com.apple.Automator 错误 -212。)”</p>

有人可以帮忙吗?谢谢!

或者,如果有人知道实现我目标的更好方法,请分享。

标签: macosapplescriptpowerpoint

解决方案


有时您需要一次完成每个过程,以隔离产生错误的原因。首先让我们看看这段代码是否会选择橡皮擦工具。
将以下 AppleScript 代码粘贴到新的 Script Editor.app 文档中。您可以直接从该文档运行代码。如果代码适合您,则尝试将其粘贴到您的 Automator 工作流程中。

tell application "Microsoft PowerPoint"
    activate
    repeat until frontmost
        delay 0.1
    end repeat
end tell

tell application "System Events"
    repeat while not (exists of radio button 3 of tab group 1 of window 1 of application process "PowerPoint")
        delay 0.1
    end repeat
    if not (exists of menu button "Eraser" of group 1 of scroll area 1 of tab group 1 of window 1 of application process "PowerPoint") then
        click radio button 3 of tab group 1 of window 1 of application process "PowerPoint"
        delay 0.1
        if value of menu button 1 of group 1 of scroll area 1 of tab group 1 of window 1 of application process "PowerPoint" is 0 then
            click menu button "Eraser" of group 1 of scroll area 1 of tab group 1 of window 1 of application process "PowerPoint"
        end if
    else
        delay 0.1
        if value of menu button 1 of group 1 of scroll area 1 of tab group 1 of window 1 of application process "PowerPoint" is 0 then
            click menu button "Eraser" of group 1 of scroll area 1 of tab group 1 of window 1 of application process "PowerPoint"
        end if
    end if
end tell

在此处输入图像描述

确保将 Automator.app、Script Editor.app、System Events.app 和 PowerPoint.app... 以及脚本(如果它保存为 .app)添加到 System Preferences > Security > Privacy > Accessibility 应用程序列表. 然后再次将这些相同的项目添加到系统偏好设置 > 安全 > 隐私 > 全盘访问应用程序列表。

在此处输入图像描述

此外,如果您将脚本或 Automator 工作流程保存为应用程序,则无论何时您进行更改并再次保存该文件,您都需要返回并再次将其重新添加到安全首选项中的这些应用程序列表中。


推荐阅读