【发布时间】: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