【问题标题】:How to open word document with known password using applescript?如何使用applescript打开已知密码的word文档?
【发布时间】:2019-05-13 06:21:43
【问题描述】:

我需要通过 AppleScript 打开受保护的 Microsoft Word 文档。 我知道密码,但我不知道如何使用 AppleScript 对其进行编码。

我尝试了一些 AppleScript 代码的变体,但没有成功。

set the myfile to ("/Users/alemac/Desktop/teste.docx")
tell application "Microsoft Word"
    open myfile password document "123"
end tell

Word 打开文件(就像 Finder 一样),打开密码对话框等待密码。

【问题讨论】:

    标签: ms-word passwords applescript


    【解决方案1】:

    在多次运行您的 AppleScript 代码版本后,open myfile password document 命令实际上为我工作了 3 或 4 次。最终它停止工作,每次都打开密码对话框。在绞尽脑汁想弄清楚为什么会这样之后,将近一个小时,我不情愿地决定使用 UI 脚本来处理密码对话框,以防它抬起丑陋的脑袋。

    此 AppleScript 代码适用于我使用最新版本的 macOS Mojave 和 Microsoft Word 版本 16.24

    set the myfile to (path to desktop as text) & "teste.docx"
    set thePassword to 123
    
    tell application "Microsoft Word"
        activate
        ignoring application responses
            open myfile password document thePassword
            delay 1
        end ignoring
    end tell
    
    try
        tell application "System Events"
            repeat until exists of window "Password" of application process "Word"
                delay 0.1
            end repeat
            click window "Password" of application process "Word"
            delay 0.2
            click text field 1 of window "Password" of application process "Word"
            delay 0.2
            keystroke thePassword
            delay 0.2
            keystroke return
        end tell
    end try
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多