当我将外接显示器插入Macbook并将其唤醒时,显示屏的分辨率通常是错误的。在Mountain Lion之前,我能够运行以下AppleScript来检测显示:
tell application "System Preferences" to activate
tell application "System Events"
tell process "System Preferences"
click menu item "Displays" of menu "View" of menu bar 1
tell button "Detect Displays" of window 1 to click
end tell
end tell
tell application "System Preferences" to quit
但是,对于10.8,“检测显示”按钮要求您按选项键显示它,因此脚本会出现以下错误:
错误“系统事件出错:无法获取按钮\”检测 显示进程“系统首选项”的窗口1的“。”数 -1728来自过程“系统偏好”的窗口1的“检测显示”按钮
我的申请技巧不够简单,我的谷歌也没有让我偶然发现答案。
如何修改脚本以单击现在隐藏的检测显示按钮?
答案 0 :(得分:8)
试试这个......
tell application "System Preferences"
activate
reveal pane "com.apple.preference.displays"
end tell
delay 0.5
tell application "System Events"
tell process "System Preferences"
try --don't even consider not using a try block!
key down option
delay 0.2
click button "Detect Displays" of window 1
delay 0.2
key up option
on error --logging out is the only other way to clear these
key up option
end try
end tell
end tell