【问题标题】:closing pop up with AppleScript使用 AppleScript 关闭弹出窗口
【发布时间】:2018-04-21 14:28:24
【问题描述】:

我正在使用 AppleScript 将一堆 PDF 文件转换为 TXT 文件:

set homeFolder to path to home folder as text
set sourceFolder to homeFolder & "pdffolder:"
set txtFolder to homeFolder & "txtfolder:"

tell application "Finder"
    set fileSet to get every file of folder sourceFolder
end tell

activate application "Adobe Acrobat Pro"
repeat with aFile in fileSet
    set currentFile to aFile as text
    set currentFileName to name of aFile
    set outFile to txtFolder & text 1 thru -5 of currentFileName & ".txt"
    with timeout of 360000 seconds
        tell application "Adobe Acrobat Pro"
            open currentFile
            try
                save active doc to file outFile using conversion "com.adobe.acrobat.plain-text"
                close active doc saving no
            on error
                tell application "System Events" to tell application "Adobe Acrobat Pro"
                    keystroke return
                end tell
            end try
        end tell
    end timeout
end repeat

这适用于超过 90% 的 PDF。但是其中一些有奇怪的字符,导致以下弹出窗口:

如何关闭 AppleScript 中的弹出窗口?我脚本中的 on error 子句应该这样做,但它不起作用。也许是因为弹出窗口不是错误,而是弹出窗口;但我不知道如何治疗。

编辑

这是我最接近的:

set homeFolder to path to home folder as text
set sourceFolder to homeFolder & "pdffolder:"
set txtFolder to homeFolder & "txtfolder:"

tell application "Finder"
    set fileSet to get every file of folder sourceFolder
end tell

activate application "Adobe Acrobat Pro"
repeat with aFile in fileSet
    set currentFile to aFile as text
    set currentFileName to name of aFile
    set outFile to txtFolder & text 1 thru -5 of currentFileName & ".txt"
    with timeout of 120 seconds
        tell application "Adobe Acrobat Pro"
            open currentFile
            try
                save active doc to file outFile using conversion "com.adobe.acrobat.plain-text"
                close active doc saving no
            on error
                tell application "System Events" to tell process "Notification Center"
                    keystroke return
                end tell
                close active doc saving no
            end try
        end tell
    end timeout
end repeat

所以,在弹出窗口挂在那里 120 秒后,我强制出现超时错误。我通过创建keystroke return 来处理该错误,这会消除弹出窗口并保持循环向前移动。但是,丑得要命 - 120 秒的等待会减慢速度。

【问题讨论】:

    标签: applescript acrobat


    【解决方案1】:

    很遗憾,这是不可能的。

    如果出现 Acrobat 错误,save 行将被挂起并出现对话窗口。 实际上,脚本挂起save 行中,并在用户单击OK 按钮后恢复。不会引发 AppleScript 错误。

    【讨论】:

    • 我明白了。非常感谢(再次!)。我写了一个丑陋的hack,在执行超时后我做了一个keystroke return(这发生在X秒后弹出窗口挂在那里之后)。这是我发现的唯一方法,可以避免每次出现弹出窗口时都必须单击“确定”。我希望有更好的方法来做到这一点,但我错了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多