Apple ScriptでANSI⇔JIS切替
JIS配列のMacとANSI配列のメカニカルキーボードを所有していて、どちらも同じくらいの頻度で利用するのですが、設定アプリでいちいち切り替えしなければならず、「US配列とJIS配列のキーボードの設定を瞬時に変える (Mac)」(https://kyogom.com/tech/ansi-to-jis/)で配列を変更していました。しかし、Montereyにアップグレードしたところ「アクション“AppleScriptを実行”でエラーが起きました: “System Eventsでエラーが起きました: button "スキップ" of window "キーボード設定アシスタント" of process "KeyboardSetupAssistant"を取り出すことはできません。”
」とエラーメッセージが出て使えなくなってしまいました。おそらくUIの変更で合わなくなったと思われます。 スクリプトを書こうにもどうすればいいのかわからないため、コミュニティで相談したいと思い、投稿しました。回答よろしくおねがいします。
Big Surまで利用できていたApple Scriptを載せておきます。
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
delay 0.4
end tell
tell application "System Events"
tell process "System Preferences"
tell tab group 1 of window "キーボード"
click button "キーボードの種類を変更…"
delay 0.4
end tell
end tell
tell window "キーボード設定アシスタント" of process "KeyboardSetupAssistant"
click button "続ける"
tell application "System Events" to keystroke "z" using command down
delay 0.4
click button "スキップ"
delay 0.4
tell radio group 1 of group 1
click radio button "JIS(日本語)"
end tell
click button "完了"
end tell
end tell
MacBook Air (2020 or later)