1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AppleScript キーボードの配列の設定を自動的に変更するスクリプト

Last updated at Posted at 2021-01-10

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?