用AppleScript关闭弹出窗口
我正在使用AppleScript将一组PDF文件转换为TXT文件:用AppleScript关闭弹出窗口,applescript,acrobat,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 so
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秒后,我强制执行超时错误。我通过执行
击键返回来处理该错误,这将取消弹出窗口并保持循环向前移动。但是,还是很难看——120秒的等待让事情变慢了。不幸的是,这是不可能的
如果发生Acrobat错误,保存
行将暂停,并显示对话框窗口。
实际上,脚本挂起在save
行中,并在用户单击OK
按钮后恢复。不会抛出AppleScript错误。我明白了。非常感谢(再次!)。我写了一个丑陋的黑客程序,在执行超时后(在弹出窗口在X秒后挂起后发生),我进行了一次击键返回。这是我发现的避免每次出现弹出窗口时都必须单击“确定”的唯一方法。我希望有更好的方法来做这件事,但我错了。