Automatorにキーボード設定をやってもらう
外付けのキーボードがdefaultのキーボードと配列が異なるので、キーボード設定を変える必要がありました。何度も手動でやるのが面倒だったので、ショートカットで自動にできるようにスクリプトを作りました。
本当は、外付けキーボードがつながったときに、自動で切り替わるといいんですが、その設定方法がよくわからなかったので。
JIS配列へ
tell application "System Preferences" to quit
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 "スキップ" of sheet 1
delay 0.4
tell radio group 1 of group 1
click radio button "JIS(日本語)"
end tell
click button "完了"
end tell
end tell
tell application "System Preferences" to quit
US配列へ
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"
delay 0.4
click button "スキップ" of sheet 1
delay 0.4
tell radio group 1 of group 1
click radio button "ANSI(米国その他)"
end tell
click button "完了"
end tell
end tell
tell application "System Preferences" to quit