【问题标题】:GUI automation with AppleScript - How to click a button in the script使用 AppleScript 实现 GUI 自动化 - 如何单击脚本中的按钮
【发布时间】:2014-02-27 23:09:52
【问题描述】:

我正在尝试编写一个将使用 PowerPoint 的 Save as Pictures... 函数的 AppleScript,但我正在与 AppleScript 搏斗。这就是我所拥有的:

set p to "file.pptx"

tell application "Microsoft PowerPoint"
    launch
    open p
    delay 2
    click menu item "Save as Pictures..." of menu bar item "File" of menu bar 1
end tell

它没有做我想要的。我得到的具体错误是:

script error: Expected end of line, etc. but found class name. (-2741)

我不知道该怎么办。我已经尝试了各种各样的东西,但我似乎无法点击正确的菜单项。我正在使用 OSX 10.9 和 PowerPoint 2011(版本 14.3.2)

更新:

这是我现在拥有的脚本:

set p to "file.pptx"

tell application "Microsoft PowerPoint"
    launch
    open p
end tell

delay 2

tell application "System Events"
    tell process "PowerPoint"
        click menu item "Save as Pictures..." of menu 1 of menu bar item "File" of menu bar 1
    end tell
end tell

我收到了execution error: Microsoft PowerPoint got an error: Parameter error. (-50)

【问题讨论】:

  • 好主意,但事实证明这是不正确的。不过感谢您的帮助!

标签: macos applescript powerpoint osx-mavericks


【解决方案1】:

GUI 自动化一般通过“系统事件”应用完成。

您还需要在尝试打开文件之前提供文件的完整路径。

这就是您正确开始攻击 PowerPoint 的方式。

set p to POSIX file "/Users/drew/Desktop/file.pptx"

tell application "Microsoft PowerPoint"
    launch
    open p
end tell

delay 2

tell application "System Events"
    tell process "PowerPoint"
        click menu item "Save as Pictures..." of menu 1 of menu bar item "File" of menu bar 1
    end tell
end tell

【讨论】:

  • 感谢您的帮助,但这给了我一个不同的错误:execution error: Microsoft PowerPoint got an error: Parameter error. (-50),我将我现在拥有的整个脚本添加到了问题中。我尝试了一些变体(流程/应用程序、“PowerPoint”/“Microsoft PowerPoint”等),但似乎总是遇到同样的错误。我什至不知道脚本的哪一部分是错误的。
  • 也许您需要启用对辅助设备的访问权限,看起来它在小牛队中有所改变。看看这个tekrevue.com/… 并添加电源点。
  • @Drew 刚刚注意到您没有使用 pptx 文件的完整路径,这可能是参数错误。已编辑我的答案以显示这一点。
  • 原来你们都是对的。感谢大家的帮助!
猜你喜欢
  • 2013-10-17
  • 2015-07-06
  • 1970-01-01
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 2012-08-30
  • 2020-09-01
  • 2011-08-22
相关资源
最近更新 更多