SSブログ

システムイベントを使って入力モードを変更する [AppleScript辞書はつくれるか?]

このページの情報はMacOS12.x以降では使用できないようです。

新しい記事を用意しましたので下記のアドレスをご確認ください。




操作の自動化をする際に意外と邪魔な挙動をすることがある、テキスト入力モード。

テキストエリアに英字を出力していたつもりが、なぜかかな入力の変換待ち状態になってたりすることがある。

逆に、日本語を使いたいのに英数字や記号などの化け化けになってしまうとか。

これをコントロールできないかとやってみた。

 

ss190327a.jpg


ss190327b.jpg




(*

    画面右上のプルダウンメニューである"SystemUIServer"を操作する.

    メニューの中から該当するアイテムを探し、疑似クリックをする。

*)

 

my inputmode("ひらがな")

 

on inputmode(thelanguage)

    set flg to false

    tell application "System Events"

        tell process "SystemUIServer" --|SystemUIServerの呼び出し|

            launch

            

            --|メニューバーにある全てのメニュー名の取得|

            tell menu bar 1

                set menuBerItem to name of (every UI element)

                --|それぞれのメニューの中のアイテムを順に取得|

                repeat with manuNo from 1 to (count of menuBerItem)

                    tell menu bar item manuNo

                        tell menu 1

                            try

                                set menuItem to name of (every UI element)

                                --|該当するアイテムを探す|

                                set itemNo to 0

                                repeat with itemNo from 1 to (count of menuItem)

                                    if (item itemNo of menuItem) contains thelanguage then

                                        try

                                            --|メニューが見つかった場合に疑似クリック|

                                            click menu item itemNo

                                            set flg to true

                                        end try

                                        exit repeat

                                    end if

                                end repeat

                            end try

                        end tell

                    end tell

                    if flg then exit repeat

                end repeat

            end tell

            if flg then click menu bar item manuNo of menu bar 1

            

        end tell

    end tell

    

    return flg

 

end inputmode



※ 一部修正しました(3/28)
 
MacOSの標準の入力ソースと、ことえりと、ATOKならこれでいけそうだが、グーグル日本語入力が使えるかは試していない。
知らないだけで、もっとスマートに変更するやり方ってあるのかもしれないなぁ。

nice!(1)  コメント(0) 
共通テーマ:パソコン・インターネット

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。