일반용과 논문용의 구두점 입력 스타일을 한번에 전환

머리


、。,.를 한 번에 전환할 수 있는 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를 선택합니다.



그런 다음 나타나는 텍스트 상자에 다음 명령을 입력합니다.
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을 이용한다. 구두점은 항상 ,.로 한다.
  • 좋은 웹페이지 즐겨찾기