用AppleScript关闭弹出窗口

时间:2018-04-21 14:28:25

标签: applescript acrobat

我正在使用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。但其中一些有奇怪的字符,导致以下弹出:

enter image description here 如何解除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秒的等待会让事情变得缓慢。

1 个答案:

答案 0 :(得分:1)

不幸的是,这是不可能的。

如果发生Acrobat错误,save行将暂停,并显示对话框窗口。 实际上,脚本save行中挂起,并在用户点击OK按钮后继续。不会抛出AppleScript错误。