我使用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秒的等待慢下来的事情。
发布于 2018-04-21 15:37:15
不幸的是这是不可能的。
如果发生Acrobat错误,则挂起save行,并显示对话框窗口。实际上,脚本挂在save行中,并在用户单击OK按钮后继续运行。不会引发AppleScript错误。
https://stackoverflow.com/questions/49956783
复制相似问题