4

外部モニターを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では、[表示の検出]ボタンを押すには、Optionキーを押して表示する必要があるため、スクリプトで次のエラーが発生します。

エラー「システムイベントでエラーが発生しました:プロセス「システム環境設定」のウィンドウ1の「ディスプレイの検出」ボタンを取得できません。」プロセス「システム環境設定」のウィンドウ1の「ディスプレイの検出」ボタンからの番号-1728

私のapplescriptスキルは初歩的ではなく、私のgoogle-fuは私が答えに出くわすことを可能にしませんでした。

スクリプトを変更して、非表示になっているディスプレイの検出ボタンをクリックするにはどうすればよいですか?

4

1 に答える 1

10

これを試して...

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
于 2012-09-28T13:47:02.760 に答える