首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用AppleScript关闭弹出

用AppleScript关闭弹出
EN

Stack Overflow用户
提问于 2018-04-21 14:28:24
回答 1查看 85关注 0票数 0

我使用AppleScript将一堆PDF文件转换为TXT文件:

代码语言:javascript
复制
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子句应该能做到这一点,但它不起作用。也许是因为弹出不是一个错误,而是一个弹出,但我不知道如何对待它。

编辑

这是我最接近的:

代码语言:javascript
复制
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秒的等待慢下来的事情。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-21 15:37:15

不幸的是这是不可能的。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49956783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档