I use 2 KEYBOARD LAYOUT (input source in system preference of the mac)
please
i want to set icon that show on the touch bar:
icon that show only when non ENGLISH KEYBOARD LAYOUT is active
when ENGLISH KEYBOARD LAYOUT is active i do not want to see the icon in the touch bar
Under "Touch Bar", create an action, and choose "Shell Script/Task".
Put whatever name you want to "Widget Identifier".
I put "Current Input Method".
Set how often you want it to check the current input method.
I put every 2 seconds.
Paste the script to the box. You will have to edit the script for your own need (this is the key step!).
You may need to open ~/Library/Preferences/com.apple.HIToolbox.plist and see the target string for yourself.
I did that, because my keyboards are a bit complicated. See my comments in the code below.
# Most natively installed keyboards can be detected by (U.S., Greek, etc., including the SBL Hebrew keyboard):
NativeKeyboards=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep 'KeyboardLayout Name' | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')
# I also used Squirrel, which have to be checked by:
Squirrel=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep -w 'Input Mode' | head -1 | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')
# I also use Keyman - It does not show the keyboard name. But I have only Hebrew installed in Keyman.
Hebrew=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep -w 'Bundle ID' | tail -n1 | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')
# I commented the English part below, because you don't want it to show when it is English.
# Otherwise, remove the 4 '#'s below, and connect 'el` with 'if`, make them into `elif`.
#if [[ $NativeKeyboards == "U.S." ]]
#then
# echo ๐บ๐ธ
#el
if [[ $NativeKeyboards == "Greek Polytonic" ]]
then
echo ๐ฌ๐ท
elif [[ $NativeKeyboards == "Biblical Hebrew - SIL" ]]
then
echo "SBL"
elif [[ $Squirrel == "im.rime.inputmethod.Squirrel" ]]
then
echo ๐จ๐ณ
elif [[ $Hebrew == "keyman.inputmethod.Keyman" ]]
then
echo ๐ฎ๐ฑ
fi
You may test run the script by clicking the "Run Script Now" button.
You may also head to "Common" and do other customizations.
One option might be useful: "Always show, even if other global actions are hidden."