Archive for the '文字入力制御(Input Method)' Category

2017/01/22 InputManager.frameworkでIMを切り換える

オープンソースのフレームワーク「InputManager.framework」(By Jens Nockert)を使って、IMを切り替えるじっけんを行うAppleScriptです。

im1.png

im2.png
▲これら2つ「ひらがな」「英字」の切り替えを10回繰り返します

実行のためにはInputManager.frameworkをビルドして、~/Library/Frameworksに入れておく必要があります。

本Scriptの実行は言語環境を「日本語」にしてあり、macOS標準のIM「日本語入力プログラム」を利用できるようにしてある必要があります。また、本AppleScriptはControl-Command-RでScript Editor上で明示的にフロントエンド・プロセスで実行する必要があります。

AppleScript名:InputManagerでIMを切り換える
– Created 2017-01-22 by Takaaki Naganoya
– 2017 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”
use framework “InputManager” –https://github.com/jensnockert/input-manager
–http://piyocast.com/as/archives/4401

–Caution: This script runs on only Japanese language environment

set cList to current application’s CSInputSource’s all()
set dList to (cList’s valueForKey:“localizedName”)
set aRes to ((dList’s indexOfObject:“ひらがな”) as integer) –”Hiragana” in Japanese
set bRes to ((dList’s indexOfObject:“英字”) as integer) –”English Letters” in Japanese

set hiraKey to cList’s objectAtIndex:aRes
set engKey to cList’s objectAtIndex:bRes

repeat 10 times
  hiraKey’s |select|()
  
delay 1
  
engKey’s |select|()
  
delay 1
end repeat

★Click Here to Open This Script 

AppleScript名:IMのメニュー表示名を取得する
– Created 2017-01-22 by Takaaki Naganoya
– 2017 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”
use framework “InputManager” –https://github.com/jensnockert/input-manager
–http://piyocast.com/as/archives/4401

set cList to (current application’s CSInputSource’s all()’s valueForKey:“localizedName”) as list
–>  {”ひらがな”, “英字”, “カタカナ”, “日本語”, “かなパレット”, “com.apple.PressAndHold”, “絵文字と記号”, “キーボードビューア”, “EmojiFunctionRowIM_Extension”}

★Click Here to Open This Script 

2015/09/28 IMの状態を取得・設定する

Shane StanleyのBridgePlus v1.2で新たに実装された「IMまわりの制御を行う機能」を用いて、IMの状態を取得・設定するAppleScriptです。Shane、本当にありがとう! Many Thanks!!

日本語Scripterの長年の懸案事項であった「日本語入力の状態の取得および設定」を、GUI Scriptingを使用せずに行えます。

fig0.png

自分もひそかに「Cocoaの機能を呼び出してできないか?」と独自に(NSTextInputContextあたりを)調べていた最中だったので、Shaneから「こんなのできたよ」と教えてもらった時には腰を抜かしました。

さまざまなアプリケーションの自動化を行うさいに、IMの状態取得と設定は欠くべからざる機能なのですが、GUI Scripting経由で強引に設定するやり方はいまひとつ信頼性が低く(Applet内から実行したときに効かないことがあるのはなんでだろー)、とてつもなく重要な機能の割に長年ASの標準機能に実装もされてきませんでした。

もう、オーストラリアに足を向けて寝られません。カナダ(Mark Alldritt)、アメリカのバーモント州(Bill Cheeseman)にも足を向けて寝られません(クパティーノに足を向けて寝るべき)。

ただ、実験したところ機能が「強力すぎる」点も見受けられ、たとえばフランス語を使わない設定になっている環境でフランス語のIMを呼び出すと・・・呼び出せるうえに、システム環境設定の「言語と地域」にいきなりフランス語が追加されます。このことはよーーく覚えておく必要があります(調子に乗って各種IMを呼び出しまくると、「言語と地域」にいろんな言語が追加されます)。

また、com.apple.inputmethod.ironwoodは音声入力に該当するようですが、これを呼び出しても音声認識による入力状態には移行しませんでした。惜しい、おしすぎる!(^ー^;;

fig1.png

fig2.png

fig3.png

fig4.png

AppleScript名:IMの状態を取得・設定する
– Created 2015-09-16 by Takaaki Naganoya
– 2015 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”
use BridgePLus : script “BridgePlus” version “1.2″ –1.2より古いバージョン(1.1など)ではこの機能が存在しない

load framework

set y to current application’s SMSForder’s availableInputSourceIDs()
–>  (NSArray) {”com.apple.inputmethod.Kotoeri.Japanese”, “com.apple.inputmethod.Kotoeri.Roman”, “com.apple.inputmethod.Kotoeri.Japanese.Katakana”, “com.apple.inputmethod.Kotoeri”, “com.apple.50onPaletteIM”, “com.apple.inputmethod.ironwood”, “com.apple.CharacterPaletteIM”, “com.apple.KeyboardViewer”}

set y to current application’s SMSForder’s allAvailableInputSourceIDs()
–>  (NSArray) {”com.apple.inputmethod.Kotoeri.Japanese”, “com.apple.inputmethod.Kotoeri.Roman”, “com.apple.inputmethod.Kotoeri.Japanese.Katakana”, “com.apple.inputmethod.Kotoeri”, “com.apple.50onPaletteIM”, “com.apple.inputmethod.ironwood”, “com.apple.CharacterPaletteIM”, “com.apple.KeyboardViewer”, “com.apple.keylayout.US”, “com.apple.SyntheticRomanMode”, “com.apple.keylayout.Czech-QWERTY”, “com.apple.keylayout.Czech”, “com.apple.keylayout.Estonian”, “com.apple.keylayout.Hungarian-QWERTY”, “com.apple.keylayout.Hungarian”, “com.apple.keylayout.Latvian”, “com.apple.keylayout.Lithuanian”, “com.apple.keylayout.PolishPro”, “com.apple.keylayout.Polish”, “com.apple.keylayout.Slovak”, “com.apple.keylayout.Slovak-QWERTY”, “com.apple.keylayout.Bulgarian-Phonetic”, “com.apple.keylayout.Bulgarian”, “com.apple.keylayout.Byelorussian”, “com.apple.keylayout.Macedonian”, “com.apple.keylayout.Russian-Phonetic”, “com.apple.keylayout.Russian”, “com.apple.keylayout.RussianWin”, “com.apple.keylayout.Serbian”, “com.apple.keylayout.Ukrainian-PC”, “com.apple.keylayout.Ukrainian”, “com.apple.keylayout.Colemak”, “com.apple.keylayout.Dvorak-Left”, “com.apple.keylayout.Dvorak-Right”, “com.apple.keylayout.Dvorak”, “com.apple.keylayout.DVORAK-QWERTYCMD”, “com.apple.keylayout.KANA”, “com.apple.keylayout.Australian”, “com.apple.keylayout.Austrian”, “com.apple.keylayout.Belgian”, “com.apple.keylayout.Brazilian-ABNT2″, “com.apple.keylayout.Brazilian”, “com.apple.keylayout.British-PC”, “com.apple.keylayout.British”, “com.apple.keylayout.Canadian-CSA”, “com.apple.keylayout.Canadian”, “com.apple.keylayout.Danish”, “com.apple.keylayout.Dutch”, “com.apple.keylayout.Finnish”, “com.apple.keylayout.French-PC”, “com.apple.keylayout.French-numerical”, “com.apple.keylayout.French”, “com.apple.keylayout.German”, “com.apple.keylayout.Irish”, “com.apple.keylayout.Italian-Pro”, “com.apple.keylayout.Italian”, “com.apple.keylayout.Norwegian”, “com.apple.keylayout.Portuguese”, “com.apple.keylayout.Spanish-ISO”, “com.apple.keylayout.Spanish”, “com.apple.keylayout.Swedish-Pro”, “com.apple.keylayout.Swedish”, “com.apple.keylayout.SwissFrench”, “com.apple.keylayout.SwissGerman”, “com.apple.keylayout.USInternational-PC”, “com.apple.keylayout.2SetHangul”, “com.apple.keylayout.AfghanDari”, “com.apple.keylayout.AfghanPashto”, “com.apple.keylayout.AfghanUzbek”, “com.apple.keylayout.Anjal”, “com.apple.keylayout.Arabic-AZERTY”, “com.apple.keylayout.Arabic-NorthAfrica”, “com.apple.keylayout.Arabic-QWERTY”, “com.apple.keylayout.Arabic”, “com.apple.keylayout.ArabicPC”, “com.apple.keylayout.Armenian-HMQWERTY”, “com.apple.keylayout.Armenian-WesternQWERTY”, “com.apple.keylayout.Azeri”, “com.apple.keylayout.Bangla-QWERTY”, “com.apple.keylayout.Bangla”, “com.apple.keylayout.CangjieKeyboard”, “com.apple.keylayout.Cherokee-Nation”, “com.apple.keylayout.Cherokee-QWERTY”, “com.apple.keylayout.Croatian”, “com.apple.keylayout.Croatian-PC”, “com.apple.keylayout.Devanagari-QWERTY”, “com.apple.keylayout.Devanagari”, “com.apple.keylayout.Faroese”, “com.apple.keylayout.FinnishExtended”, “com.apple.keylayout.FinnishSami-PC”, “com.apple.keylayout.Georgian-QWERTY”, “com.apple.keylayout.Greek”, “com.apple.keylayout.GreekPolytonic”, “com.apple.keylayout.Gujarati-QWERTY”, “com.apple.keylayout.Gujarati”, “com.apple.keylayout.Gurmukhi-QWERTY”, “com.apple.keylayout.Gurmukhi”, “com.apple.keylayout.Hawaiian”, “com.apple.keylayout.Hebrew-QWERTY”, “com.apple.keylayout.Hebrew”, “com.apple.keylayout.Hebrew-PC”, “com.apple.keylayout.Icelandic”, “com.apple.keylayout.Inuktitut-Nunavut”, “com.apple.keylayout.Inuktitut-Nutaaq”, “com.apple.keylayout.Inuktitut-QWERTY”, “com.apple.keylayout.InuttitutNunavik”, “com.apple.keylayout.IrishExtended”, “com.apple.keylayout.Jawi-QWERTY”, “com.apple.keylayout.Kannada-QWERTY”, “com.apple.keylayout.Kannada”, “com.apple.keylayout.Kazakh”, “com.apple.keylayout.Khmer”, “com.apple.keylayout.Kurdish-Sorani”, “com.apple.keylayout.Malayalam-QWERTY”, “com.apple.keylayout.Malayalam”, “com.apple.keylayout.Maltese”, “com.apple.keylayout.Maori”, “com.apple.keylayout.Myanmar-QWERTY”, “com.apple.keylayout.Nepali”, “com.apple.keylayout.NorthernSami”, “com.apple.keylayout.NorwegianExtended”, “com.apple.keylayout.NorwegianSami-PC”, “com.apple.keylayout.Oriya-QWERTY”, “com.apple.keylayout.Oriya”, “com.apple.keylayout.Persian-QWERTY”, “com.apple.keylayout.Persian”, “com.apple.keylayout.Persian-ISIRI2901″, “com.apple.keylayout.Romanian-Standard”, “com.apple.keylayout.Romanian”, “com.apple.keylayout.Sami-PC”, “com.apple.keylayout.Serbian-Latin”, “com.apple.keylayout.Sinhala-QWERTY”, “com.apple.keylayout.Sinhala”, “com.apple.keylayout.Slovenian”, “com.apple.keylayout.SwedishSami-PC”, “com.apple.keylayout.Tamil99″, “com.apple.keylayout.Telugu-QWERTY”, “com.apple.keylayout.Telugu”, “com.apple.keylayout.Thai-PattaChote”, “com.apple.keylayout.Thai”, “com.apple.keylayout.TibetanOtaniUS”, “com.apple.keylayout.Tibetan-QWERTY”, “com.apple.keylayout.Tibetan-Wylie”, “com.apple.keylayout.Turkish-QWERTY-PC”, “com.apple.keylayout.Turkish-QWERTY”, “com.apple.keylayout.Turkish”, “com.apple.keylayout.USExtended”, “com.apple.keylayout.UnicodeHexInput”, “com.apple.keylayout.Urdu”, “com.apple.keylayout.Uyghur”, “com.apple.keylayout.Vietnamese”, “com.apple.keylayout.Welsh”, “com.apple.keylayout.ZhuyinBopomofo”, “com.apple.keylayout.390Hangul”, “com.apple.keylayout.3SetHangul”, “com.apple.keylayout.GJCRomaja”, “com.apple.keylayout.HNCRomaja”, “com.apple.keylayout.WubihuaKeyboard”, “com.apple.keylayout.WubixingKeyboard”, “com.apple.keylayout.ZhuyinEten”, “com.apple.inputmethod.PluginIM”, “com.apple.inputmethod.Ainu”, “com.apple.inputmethod.ink.inkserver”, “com.apple.inputmethod.Korean”, “com.apple.PressAndHold”, “com.apple.inputmethod.SCIM”, “com.apple.inputmethod.AssistiveControl”, “com.apple.inputmethod.Tamil”, “com.apple.inputmethod.TCIM”, “com.apple.inputmethod.ChineseHandwriting”, “com.apple.inputmethod.VietnameseIM”, “com.apple.inputmethod.AinuIM.Ainu”, “com.apple.inputmethod.Kotoeri.Japanese.HalfWidthKana”, “com.apple.inputmethod.Kotoeri.Japanese.FullWidthRoman”, “com.apple.inputmethod.Korean.3SetKorean”, “com.apple.inputmethod.Korean.2SetKorean”, “com.apple.inputmethod.Korean.HNCRomaja”, “com.apple.inputmethod.Korean.390Sebulshik”, “com.apple.inputmethod.Korean.GongjinCheongRomaja”, “com.apple.inputmethod.SCIM.ITABC”, “com.apple.inputmethod.SCIM.WBH”, “com.apple.inputmethod.SCIM.WBX”, “com.apple.inputmethod.Tamil.AnjalIM”, “com.apple.inputmethod.Tamil.Tamil99″, “com.apple.inputmethod.TCIM.WBH”, “com.apple.inputmethod.TCIM.Zhuyin”, “com.apple.inputmethod.TCIM.Cangjie”, “com.apple.inputmethod.TCIM.ZhuyinEten”, “com.apple.inputmethod.TCIM.Jianyi”, “com.apple.inputmethod.TCIM.Pinyin”, “com.apple.inputmethod.VietnameseIM.VietnameseSimpleTelex”, “com.apple.inputmethod.VietnameseIM.VietnameseVNI”, “com.apple.inputmethod.VietnameseIM.VietnameseVIQR”, “com.apple.inputmethod.VietnameseIM.VietnameseTelex”, “jp.monokakido.inputmethod.Kawasemi”, “com.parallels.inputmethod.ParallelsIM”, “com.visionobjects.Axiotron Quickscript.TSC”, “jp.monokakido.inputmethod.Kawasemi.Japanese”, “jp.monokakido.inputmethod.Kawasemi.Japanese.HalfWidthKana”, “jp.monokakido.inputmethod.Kawasemi.Japanese.HalfWidthRoman”, “jp.monokakido.inputmethod.Kawasemi.Roman”, “jp.monokakido.inputmethod.Kawasemi.Japanese.FullWidthRoman”, “jp.monokakido.inputmethod.Kawasemi.Japanese.Katakana”, “jp.monokakido.inputmethod.Kawasemi.Japanese.Code”}

–デモ: IMのメニューで「A」と「あ」を交互に切り替える
repeat 10 times
  set x to current application’s SMSForder’s changeInputSourceTo:“com.apple.inputmethod.Kotoeri.Roman”
  
tell current application
    delay 0.5
  end tell
  
set x to current application’s SMSForder’s changeInputSourceTo:“com.apple.inputmethod.Kotoeri.Japanese”
  
tell current application
    delay 0.5
  end tell
end repeat

★Click Here to Open This Script 

AppleScript名:ironwood(音声認識入力)を呼び出したが、音声入力は始まらなかった
– Created 2015-09-16 by Takaaki Naganoya
– 2015 Piyomaru Software
use AppleScript version “2.4″
use scripting additions
use framework “Foundation”
use BridgePLus : script “BridgePlus” version “1.2″ –1.2より古いバージョン(1.1など)ではこの機能が存在しない

load framework

tell application “TextEdit” to activate
delay 3
set x to current application’s SMSForder’s changeInputSourceTo:“com.apple.inputmethod.ironwood”

★Click Here to Open This Script