環境設定→ユーザー辞書を書き出す 環境設定→ユーザー辞書登録 タブ区切りテキスト

2018年11月26日(月)

●「環境設定→ユーザー辞書を書き出す.scpt」テキストエディタにタブ区切りテキスト出力

ダウンロード「環境設定→ユーザー辞書を書き出す.scpt」(5KB)user-dictionary-export-tabT.zip(macOS 10.14 Mojave(モハベ)用)

●タブ区切りテキストから「環境設定→ユーザー辞書登録.scpt」

ダウンロード「環境設定→ユーザー辞書登録.scpt」(7KB)user-dictionary-input-tabT.zip(macOS 10.14 Mojave(モハベ)用)

メモ
「スクリプトエディタ」で実行することをお勧めします。

このアップルスクリプトサンプルは、下記の UIスクリプトの階層を探る で得た参照式を編集して作りました。 システム環境設定のキーボード→ユーザー辞書の部分でタブ区切りのテキストで書き出したり。タブ区切りテキストから入力をしていくアップルスクリプトです。 手動で入力するよりは楽といったところで、大量のユーザー辞書登録がある場合は、それなりに時間がかかるといったところです。
*注意:UIスクリプトを利用してタブキー入力やリターン入力も補助的に少し使っているので、(環境設定→ユーザー辞書登録.scpt)は、バックグラウンドで動作させないほうがいいです。
*「環境設定→ユーザー辞書登録.scpt」は、タブ区切りテキストをテキストエディタで開いて、このスクリプトを実行してください。 テキストエディタで最前面に開いている書類からシステム環境設定のユーザー辞書に登録していきます。



戻る(UIスクリプトの階層を探る)

トップページ








●このスクリプトの内容(環境設定→ユーザー辞書を書き出す.scpt)

tell application "System Preferences" to activate
tell application "System Events"
repeat 7 times
if exists menu item "キーボード" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "System Preferences" then exit repeat
delay 1
end repeat
click menu item "キーボード" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "System Preferences"
delay 1
click radio button "ユーザ辞書" of tab group 1 of window "キーボード" of application process "System Preferences"
set string_ to ""
repeat with row_ in rows of table 1 of scroll area 1 of tab group 1 of window "キーボード" of application process "System Preferences" as list
set string_ to string_ & value of text field 1 of UI element 1 of row_ & tab as string
set string_ to string_ & value of text field 1 of UI element 2 of row_ & return as string
end repeat
end tell
tell application "TextEdit" to make new document at beginning with properties {text:string_ as string}

●このスクリプトの内容(環境設定→ユーザー辞書登録.scpt)

tell application "System Preferences" to activate
tell application "System Events"
repeat 7 times
if exists menu item "キーボード" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "System Preferences" then exit repeat
delay 1
end repeat
click menu item "キーボード" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "System Preferences"
delay 1
click radio button "ユーザ辞書" of tab group 1 of window "キーボード" of application process "System Preferences"
end tell
tell application "TextEdit" to set string_ to text of first document as string
tell application "System Events"
repeat with line_ in paragraphs of string_ as list
if line_ as string is not "" and (offset of tab in line_) is not 0 then
set my text item delimiters to tab
click button 1 of group 1 of tab group 1 of window "キーボード" of application process "System Preferences"
delay 1
--keystroke tab
set value of text field 1 of UI element 1 of last row of table 1 of scroll area 1 of tab group 1 of window "キーボード" of application process "System Preferences" to first text item of line_ as string
keystroke tab
set value of text field 1 of UI element 2 of last row of table 1 of scroll area 1 of tab group 1 of window "キーボード" of application process "System Preferences" to last text item of line_ as string
keystroke return
delay 1
select last row of table 1 of scroll area 1 of tab group 1 of window "キーボード" of application process "System Preferences"
end if
end repeat
end tell