しばらく返答が寄せられていないようです。 再度ディスカッションを開始するには、新たに質問してください。

AppleScript でダイアログにOKするには?

以下のスクリプトでモニタの解像度を変えようと思います。


tell application "System Preferences"

activate

reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"

end tell

delay 1

tell application "System Events"

tell application process "System Preferences"

set frontmost to true

tell tab group 1 of window 1

click radio button 2 of radio group 1 -- "Scaled"

select row 5 of table 1 of scroll area 1 -- select the second row in the table to change the resolution of the monitor

end tell

end tell

end tell

ユーザがアップロードしたファイル

ユーザがアップロードしたファイル

ここで「OK」ボタンを自動で押して処理を次に継続していくにはどの様にしたらよいでしょうか。


よろしくお願いします。

Mac mini, macOS Mojave (10.14.1), null

投稿日 2018/11/15 00:41

返信
スレッドに付いたマーク ベストな回答

投稿日 2018/11/15 06:18

こんな感じでどうでしょうか?


tell application "System Preferences"
    activate
    reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell

delay 1

tell application "System Events"
    tell application process "System Preferences"
        set frontmost to true

        tell window 1
            tell tab group 1
                click radio button 2 of radio group 1
                select row 5 of table 1 of scroll area 1
            end tell

            delay 1

            if exists sheets then
                click button "OK" of sheet 1
            end if
        end tell
    end tell
end tell


ーーーーー


それか、単純に「リターンキー」を押しても大丈夫かもしれません。


[変更前]

if exists sheets then
    click button "OK" of sheet 1
end if


[変更後]

if exists sheets then
    keystroke return
end if


ーーーーー


なお、上記は High Sierra で動作確認しました。何となく大丈夫そうな気がしたのでポストしましたが、Mojave で動かない場合は申し訳ありませんが他の方の回答を待ってください。

返信: 4
スレッドに付いたマーク ベストな回答

2018/11/15 06:18 i_was5um への返信

こんな感じでどうでしょうか?


tell application "System Preferences"
    activate
    reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell

delay 1

tell application "System Events"
    tell application process "System Preferences"
        set frontmost to true

        tell window 1
            tell tab group 1
                click radio button 2 of radio group 1
                select row 5 of table 1 of scroll area 1
            end tell

            delay 1

            if exists sheets then
                click button "OK" of sheet 1
            end if
        end tell
    end tell
end tell


ーーーーー


それか、単純に「リターンキー」を押しても大丈夫かもしれません。


[変更前]

if exists sheets then
    click button "OK" of sheet 1
end if


[変更後]

if exists sheets then
    keystroke return
end if


ーーーーー


なお、上記は High Sierra で動作確認しました。何となく大丈夫そうな気がしたのでポストしましたが、Mojave で動かない場合は申し訳ありませんが他の方の回答を待ってください。

2018/11/15 19:19 Hiro__S への返信

ありがとうございました。Mojave でも問題なかったです。

click button "OK" of sheet 1

keystroke return


どちらでも動作しました。


ただ自分の

tell tab group 1 of window 1

ではボタンを押さずに止まってしまいますが

tell window 1

tell tab group 1

ではOKしてくれました。もっと勉強が必要ですね。

2018/11/15 22:56 i_was5um への返信

お役に立てて何よりです。期待通りに動いたようで。ホッとしました。


あと、tell tab group 1 of window 1 ... とするなら、こんな感じでいけると思います。


tell tab group 1 of window 1
    click radio button 2 of radio group 1
    select row 5 of table 1 of scroll area 1
end tell

delay 1

if exists sheets in window 1 then
    click button "OK" of sheet 1 in window 1
end if

AppleScript でダイアログにOKするには?

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple ID を使ってご参加ください。