Macos 运行检测显示的Applescript

Macos 运行检测显示的Applescript,macos,applescript,Macos,Applescript,当我将外置显示器插入Macbook并唤醒它时,显示器的分辨率通常是错误的。在使用Mountain Lion之前,我能够运行以下applescript来检测显示器: tell application "System Preferences" to activate tell application "System Events" tell process "System Preferences" click menu item "Displays" of menu "Vie

当我将外置显示器插入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的按钮“检测显示”

我的applescript技能还不够初级,我的google fu也没有让我偶然找到答案

如何修改脚本以单击“现在隐藏的检测显示”按钮?

试试这个

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

10.14.4在这里,这个脚本起作用了,但我必须创建一个运行该脚本的应用程序,然后通过触摸栏调用它。由于某些安全限制,您似乎无法让Automator直接输入击键,但您可以让它运行一个执行以下操作的应用程序:D