【问题标题】:How can I trigger keyboard commands via AppleScript in a Flash-generated upload prompt?如何在 Flash 生成的上传提示中通过 AppleScript 触发键盘命令?
【发布时间】:2014-03-26 18:26:26
【问题描述】:

我正在尝试通过 AppleScript 将照片上传到网站。

基本经验是:

  1. 加载站点 [完成]
  2. 点击“上传”[完成 - 在 Finder 中触发选择文件提示,但左上方仍显示 Safari]
  3. 在提示符中输入文件路径并使用:

    tell application "System Events" keystroke "g" using {shift down, command down} keystroke "/Users/myUser/Pictures/myPic.jpg" key code 36 end tell

但是,AppleScript 只是在提示出现后停止移动,并等待人工交互。如何使用 AppleScript 在这样的提示中上传图片?

Web 端的演示:http://www.uploadify.com/demos/

假设我可以通过 AppleScript 单击此演示中的“选择文件”按钮。如何继续使用AppleScript输入文件路径并提交?

【问题讨论】:

  • 类似网页体验的演示:uploadify.com/demos
  • 你是怎么点击上传按钮的?随着该代码继续处理对话框,它值得展示。
  • 也许这只是时间问题 - 尝试在发送击键之前插入延迟(也可能在 ⌘⇧-G 命令和输入文件名之间)。不用说,这不是一个可靠的解决方案。

标签: macos flash upload safari applescript


【解决方案1】:

您需要像@mklement0 所说的那样延迟代码 并确保 safari 已激活

tell application "safari"
activate
    tell application "System Events"
        keystroke "g" using {shift down, command down}            
        delay 1.6
        keystroke "/Users/myUser/Pictures/myPic.jpg"
        delay 1.6
        key code 36
    end tell
end tell

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 2013-06-13
    • 2019-04-05
    • 2011-03-22
    相关资源
    最近更新 更多