使用 AppleScript 关闭弹出窗口
closing pop up with AppleScript
我正在使用 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 秒的等待会减慢速度。
很遗憾,这是不可能的。
如果发生 Acrobat 错误,save
行将暂停并出现对话框 window。
实际上,脚本 在 save
行挂起 并在用户单击 OK
按钮后恢复。不会引发 AppleScript 错误。
我正在使用 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。但其中一些有奇怪的字符,导致以下弹出:
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 秒的等待会减慢速度。
很遗憾,这是不可能的。
如果发生 Acrobat 错误,save
行将暂停并出现对话框 window。
实际上,脚本 在 save
行挂起 并在用户单击 OK
按钮后恢复。不会引发 AppleScript 错误。