【问题标题】:Using AppleScript In Adobe Acrobat PRO DC to Reduce File Size在 Adob​​e Acrobat PRO DC 中使用 AppleScript 来减小文件大小
【发布时间】:2017-04-10 20:50:29
【问题描述】:

我正在尝试使用 AppleScript 在 Adob​​e Acrobat Pro 中打开 PDF,并在保存文件时使用“减小文件大小”选项减小文件大小。

Trying to click this element

根据 Accessibility Inspector 的说法,它具有以下层次结构: Accessibility Inspector Image

我的第一步是使用set allElem to entire contents of window "Save As PDF" 跟踪窗口中的所有元素。输出表明该元素不是按钮或复选框:

group "Reduce File Size" of group "    My Computer        " of UI element 1 of group 1 of group 1 of window "Save As PDF" of application process "AdobeAcrobat" of application "System Events"

 static text "Reduce File Size" of group 1 of group "Reduce File Size" of group "    My Computer        " of UI element 1 of group 1 of group 1 of window "Save As PDF" of application process "AdobeAcrobat" of application "System Events"        

 text field 1 of static text "Reduce File Size" of group 1 of group "Reduce File Size" of group "    My Computer        " of UI element 1 of group 1 of group 1 of window "Save As PDF" of application process "AdobeAcrobat" of application "System Events"

group 1 of group "Reduce File Size" of group "    My Computer        " of UI element 1 of group 1 of group 1 of window "Save As PDF" of application process "AdobeAcrobat" of application "System Events"

没有点击按钮,我尝试通过向窗口发送击键来解决这个问题。

tell window "Save As PDF"
    activate
    keystroke tab
    keystroke tab
    keystroke tab
    keystroke tab
    delay 1
    key code 36 --return key                            
end tell

但是“另存为 PDF”窗口似乎没有出现在前面;因此,击键不会注册到该特定窗口。

同样

tell group "Reduce File Size" of group "    My Computer        " of UI element 1 of group 1 of group 1 of window "Save As PDF" of application process "AdobeAcrobat" of application "System Events"
    set {xPosition, yPosition} to position
    set {xSize, ySize} to size
    click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
end tell

不起作用,因为由于某种原因,“另存为 PDF”窗口中没有发生单击事件。

所以现在我想知道两件事:

  1. 实际上是否有我可以单击的按钮或复选框(我是否以某种方式遗漏了可用单击事件的某些内容,例如,您可以将单击事件发送到静态文本吗?)。

  2. 为什么按键和点击事件没有在窗口中注册?

【问题讨论】:

    标签: applescript acrobat


    【解决方案1】:

    经过大量试验和错误后,activate window "Save As PDF" 似乎并没有真正激活窗口。最终,user495470's answer 解决了我的问题。

    
    tell application "System Events" to tell process "Acrobat Pro"
        perform action "AXRaise" of window "Save As PDF"
    end tell
    set frontmost to true
    

    这最终将 Adob​​e Acrobat 带到了前窗口并激活了它。以前,我所有的击键或点击都注册在脚本编辑器窗口(或终端窗口,如果我从那里运行),而不是“另存为 PDF”窗口。

    现在最终的代码变成了

    
    tell application "System Events"
            tell process "Acrobat Pro"
                delay 1
                click menu item "Save As..." of menu "File" of menu bar 1
                delay 2
                --Bring "Save As PDF" window to front
                tell application "System Events" to tell process "Acrobat Pro"
                    perform action "AXRaise" of window "Save As PDF"
                end tell
                set frontmost to true
                --Tab 4 times To Select Checkbox
                delay 0.5
                keystroke tab
                keystroke tab
                keystroke tab
                keystroke tab
                key code 36   --return key
                delay 0.5
                --Tab 4 times to select "Choose Different Folder..." button
                keystroke tab
                keystroke tab
                keystroke tab
                keystroke tab
                key code 36  --return key
                delay 0.5
        end tell
    end tell
    

    它并不完全优雅,但它确实有效。我仍然很惊讶点击“选择不同的文件夹...”不是通过以下方式实现的:

    Click Button "Choose Different Folder..." of group 2 of UI element 1 of group 1 of group 1 of window "Save As PDF"
    

    【讨论】:

    • 还有其他不需要这种方法的减小文件大小的方法。我有两个用于文件夹操作的工作流程,如果它们是位图密集的,可以减少 pdf 大小。这是一种如此简单、快速、非 UI 的方式,但我想知道 Acrobat Pro 是否也在做其他事情(如果这样做我可能会感到惊讶——我的意思是,我们只是在谈论文本吗?)
    • 该文件包含不少图像。 Acrobat Pro 在减小文件大小(22.3 MB 到 1.2 MB)和保持图像质量方面产生了最好的结果。我测试了 Apple 的 Preview 应用程序以通过脚本减小 PDF 的文件大小,但图像看起来很糟糕。
    • 是的,我绝对不会使用脚本预览来做这样的事情。
    猜你喜欢
    • 1970-01-01
    • 2020-05-26
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多