我正在尝试编写一个小AppleScript,它会单击OneNote工具栏Extension,因此我可以将其绑定到键盘快捷键。只要Safari的实例处于窗口模式,下面的脚本就可以正常工作,但是在全屏幕中它会失败并返回错误:
错误“系统事件出错:无法获取进程的窗口1”Safari \“。索引无效。”从过程“Safari”的窗口1开始编号-1719
我已将此脚本导出为应用程序,并授予其访问权限。实际上似乎全屏Safari窗口没有给出索引或不再是窗口,现在是一个不同的对象。
tell application "System Events"
tell process "Safari"
click button whose description contains "OneNote" of toolbar 1 of window 1
end tell
end tell
MacBook Pro(Retina,13英寸,2013年末) OS X El Capitan,版本:10.11.6(15G1004)
答案 0 :(得分:0)
试试这个脚本。无论Safari是否处于全屏模式,它都能正常工作:
set myButton to "OneNote"
tell application "System Events"
tell process "Safari"
set isfullscreen to value of attribute "AXFullScreen" of window 1
if isfullscreen is true then
click ((buttons of toolbar 1 of group 1 of window 1) whose description contains myButton)
else
click ((buttons of toolbar 1 of window 1) whose description contains myButton)
end if
end tell
end tell
将“OneNote”替换为您要点击的任何按钮。