使用AppleScript automation如何获取当前打开的Adobe reader文件名

使用AppleScript automation如何获取当前打开的Adobe reader文件名,applescript,adobe,Applescript,Adobe,我试过下面的代码 activate application "Adobe Reader" tell application "System Events" tell process "Adobe Reader" set currentFile to active Document end tell end tell 但我无法获取活动文档名称,我已尝试使用已打开的文档使用此代码。我甚至没有在脚本编辑器中找到任何adobe reader字典。如果您有任何建议,

我试过下面的代码

activate application "Adobe Reader"

tell application "System Events"
    tell process "Adobe Reader"
        set currentFile to active Document


    end tell
end tell

但我无法获取活动文档名称,我已尝试使用已打开的文档使用此代码。我甚至没有在脚本编辑器中找到任何adobe reader字典。如果您有任何建议,我们将不胜感激。

以下是一些可能适合您的AppleScript选项。我没有Adobe Reader,因此无法测试代码

tell application "Adobe Reader" to set currentFile to name of document 1
如果这对你不起作用,你可以试试这个

tell application "Adobe Reader" to activate

repeat until application ""Adobe Reader" is frontmost
    delay 0.1
end repeat

tell application (path to frontmost application as text) to set currentFile to name of document 1

Adobe Reader应用程序在其应用程序包中没有AppleScript字典文件,因此,除了数量非常有限的标准套件命令和UI脚本菜单栏中的AppleScript系统外,它不可编写脚本事件

如果您只想获取具有焦点的文档的名称,那么下面的示例AppleScript代码可以做到这一点:

if running of application id "com.adobe.Reader" then
    try
        tell application "System Events" to ¬
            set docName to ¬
                (get name of every menu item of menu 1 of menu bar item ¬
                    "Window" of menu bar 1 of application process ¬
                    "Acrobat Reader" whose value of ¬
                    attribute "AXMenuItemMarkChar" = "✓") as string
        return docName
    end try
end if
使用
return docName
用于测试目的,可以根据需要删除。此外,AdobeReader不需要焦点,它的窗口甚至可以最小化,脚本仍然检索名称,如其窗口菜单所示

  • 注意:这是在macOS High Sierra上使用美国英语和Adobe Acrobat Reader DC(连续发行版| 2019.021.20058)测试的,并按原样运行。其他语言和/或不同版本的Adobe Reader可能需要进行调整


注意:示例AppleScript代码仅此而已,不包含任何其他适当的错误处理。用户有责任根据需要添加任何适当的错误处理。请查看中的语句和语句。另见。此外,在适当的情况下,可能需要在事件之间使用该命令,例如延迟0.5,延迟值设置适当。

否这不起作用,其抛出错误“Adobe Reader出错:无法获取文档1的名称。”