我正在尝试使用AppleScript在Adobe Acrobat Pro中打开PDF,并在保存文件时使用“缩小文件大小”选项缩小文件大小。
根据Accessibility Inspector,它具有以下层次结构: Accessibility Inspector Image
我的第一步是使用<div ng-repeat="(key, val) in $ctrl.offer.properties">
<fieldset ng-if="val">
<h3>{{$ctrl.getLabelFor(key)}}</h3>
<md-input-container>
<input name="procent" ng-model="$ctrl.offer.properties.key.procent"/>
</md-input-container>
跟踪窗口中的所有元素。输出表明此元素不是按钮或复选框:
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"
但是“另存为PDF”窗口似乎没有出现在前面;因此,击键不会注册到该特定窗口。
类似地
tell window "Save As PDF"
activate
keystroke tab
keystroke tab
keystroke tab
keystroke tab
delay 1
key code 36 --return key
end tell
不起作用,因为出于某种原因,“另存为PDF”窗口中未发生单击事件。
所以现在我想知道两件事:
实际上是否有我可以点击的按钮或复选框(我在某种程度上错过了可用点击事件的内容,例如,您是否可以向静态文本发送点击事件?)。
为什么按键和点击事件没有在窗口中注册?
答案 0 :(得分:0)
经过大量的反复试验后,似乎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
这最终将Adobe Acrobat带到了前窗并激活了它。之前,我的所有击键或点击都是在“脚本编辑器”窗口(或终端窗口,如果我从那里运行)注册,而不是&#34;另存为PDF&#34;窗口。
现在最终的代码变为
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
它并不完全优雅,但它确实有效。点击“选择不同的文件夹...”后,我仍然感到惊讶...&#34;没有实现:
Click Button "Choose Different Folder..." of group 2 of UI element 1 of group 1 of group 1 of window "Save As PDF"