AppleScript的运行检测显示器 [英] Applescript to run Detect Displays

查看:852
本文介绍了AppleScript的运行检测显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我插上外接显示器到我的MacBook和唤醒它,显示器往往是错误的分辨率。此前山狮,我能够运行下面的AppleScript检测显示:

When I plug an external monitor into my Macbook and wake it, the display is often the wrong resolution. Prior to Mountain Lion, I was able to run the following applescript to detect displays:

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的检测显示器按钮,您需要preSS的选项键来显示它,所以该脚本提供了以下错误:

But, with 10.8, the "Detect Displays" button requires that you press the Option key to display it, and so the script gives the following error:

错误系统事件得到了一个错误:无法获取键\\检测
  显示\\进程\\窗口1系统preferences \\。数
  从-1728键检测显示器的过程窗口1系统preferences

error "System Events got an error: Can’t get button \"Detect Displays\" of window 1 of process \"System Preferences\"." number -1728 from button "Detect Displays" of window 1 of process "System Preferences"

我的AppleScript的技能低于简陋和我的谷歌福没有让我对面的答案绊倒。

My applescript skills are less than rudimentary and my google-fu has not enabled me to stumble across an answer.

如何修改脚本点击现在隐藏检测显示器按钮?

推荐答案

试试这个...

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

这篇关于AppleScript的运行检测显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆