LoginSignup
13
13

More than 5 years have passed since last update.

通常用と論文用の句読点入力スタイルを一発で切り替える

Last updated at Posted at 2015-04-22

まえがき

、。,. を一発で切り替えられるAppleScript。全国の理系大学生Macerに需要あるんじゃないかな?と思って書いてみました。ただAppleScriptは今まで全く書いたことが無い者なので、改良点などありましたら是非ご報告ください。

本編

Yosemite標準のJapaneseIM用です。

ソースコード

tell application "System Preferences"
    set current pane to pane "com.apple.preference.keyboard"
    reveal anchor "InputSources" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
    if not UI elements enabled then
        set UI element enableld to true
    end if
    tell tab group 1 of window 1 of application process "System Preferences"
        tell table 1 of scroll area 1
            select item 1 of (every row whose (name of UI element 1 is "日本語"))
        end tell
        tell pop up button 4 of scroll area 2
            click
            tell menu 1
                if selected of menu item 1 then
                    click menu item 4
                else
                    click menu item 1
                end if
            end tell
        end tell
    end tell
end tell

-- 1回ごとにシステム環境設定を終了したい場合はコメントアウトを解除
-- (但し次回の実行に時間がかかる)
-- if application "System Preferences" is running then
--     tell application "System Preferences" to quit
-- end if

使い方

上記を拡張子 .applescript で任意のディレクトリに保存し、ショートカットキー等を用いて呼び出せるようにしておきます。ここでは ~/.switch_punct_style.applescript として保存したと仮定します。

BetterTouchToolを使用する例

Globalに対して重複しないようなショートカットキーを割り振り、動作として Execute Terminal Command を選択します。

Step1

そして現れたテキストボックスに以下のコマンドを入力します。

osascript ~/.switch_punct_style.applescript

あとは設定したショートカットキーを押せば…

追記

  • JapaneseIMはChromeと相性が悪い (コピペ操作でフリーズ・勝手に日本語入力不能に)
  • GoogleIMEはSublimeText3と相性が悪い (日本語のインライン入力時にショートカットキーが競合)
  • GoogleIMEの句読点切り替えのための設定画面をAppleScriptから操作出来ない

こういった事情からGoogleIMEとJapaneseIMを両方使っていくことにしたので、両者をいい感じに切り替えてくれるスクリプトを自分用にメモしておきます。主にUSキーボードで「前の入力ソースを選択」を利用している人向けです。

tell application "System Events"
    if not UI elements enabled then
        set UI element enableld to true
    end if
    tell menu bar 1 of application process "SystemUIServer"
        tell item 1 of (every menu bar item whose description is "text input")
            if value is "英数 (Google)" or value is "ひらがな (Google)" then
                set modes to {"ひらがな", "英字"}
            else
                set modes to {"ひらがな (Google)", "英数 (Google)"}
            end if
            repeat with mode in modes
                click
                tell menu 1
                    click item 1 of (every menu item whose name is contents of mode)
                end tell
            end repeat
        end tell
    end tell
end tell

個人的に落ち着きそうな使い方

  • 普段はGoogleIMEを利用する。句読点は常に、。にする。
  • スクリプトやTeXを書くときはJapaneseIMを利用する。句読点は常に,.にする。
13
13
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
13
13