3

I use a third-party input source on Mac. This is the case I encounter:

  1. I input some English characters when I want to input Chinese so I have to delete the characters entered just now. Then switch to Chinese and type again.

  2. If I know what is the current input language, so I can switch the input language first.

  3. The input source can't display current input language but I have press Shift to switch between Chinese and English to see whether the current language is what I want.

  4. After some research, I find this repo bitbar. This repo can display some script output at the menubar. So I want some script to get the current input language of the input source.

  5. I also find this question, however this question is different from mine. It just find the input source name, not the input language.

After Googling for a long time, I didn't find a way to do this. Any one can help me? Thank you so much.

4
  • Where did you get this 3rd party input source which does both Chinese and English? It seems like any solution which have to be something which recognizes what state it is in. Presumably Keyboard Viewer would tell you that, but having that on the screen is probably not ideal... Commented Sep 6, 2016 at 10:07
  • @TomGewecke Thanks for you reply. It is RIME. Every Chinese input source can switch between English and Chinese with the same Keyboard layout. This input method I configure the shortcut <kbd>Shift</kbd> to switch between English and Chinese. The Keyboard Viewer won't tell me which state I am in.
    – aries
    Commented Sep 6, 2016 at 10:24
  • With the Apple IM’s, don’t you need to do capslock to type English? In that case it can be seen from the green light on the keyboard and the shading on Keyboard Viewer. Can you configure RIME to use capslock the same way? Commented Sep 6, 2016 at 15:03
  • @TomGewecke Yeah. This is a workaround and it works. Thank you so much. ;-)
    – aries
    Commented Sep 6, 2016 at 15:56

2 Answers 2

1

One possible work-around is to configure the input source so that Caps Lock is used to switch to English. Then you can tell the IM is in that state by the green light on the keyboard (if it has one for capslock).

1

I'm doing to go something similar, except with Japanese/ English.

I wrote the following script:

#!/usr/local/bin/bash
# Checks current keyboard input source (aka language)

#These are the strings that MacOS uses to identify the current input source
ENGLISH="U.S."
HIRIGANA="com.apple.inputmethod.Japanese"
KATANA="com.apple.inputmethod.Japanese.Katakana"

WESTERN_LANGUAGE=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep 'KeyboardLayout Name' | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')

# If the current language is not western one, then check a different variable
EASTERN_LANGUAGE=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep -w 'Input Mode' | head -1 | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')

if [ $WESTERN_LANGUAGE == $ENGLISH ]
then
  echo 🇬🇧
elif [ $EASTERN_LANGUAGE == $HIRIGANA ]
then
  echo 🇯🇵 
elif [ $EASTERN_LANGUAGE == $KATANA ]
then
  echo 🈴
fi

This determines the current language and shows a relevant emoji. You can combine it with xbar (rebranded bitbar) and show the current language in the menu bar; you'll also want to have the script run after you change the language (you can prob use iCanHazShortcut to bind a keyboard shortcut to that).

A simpler way is to go into the Mac Keyboard settings and have it show an icon for the current input source (not sure how well that works if you're using a 3rd party input source).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .