Is it possible to show current `Text Input` language on TouchBar

Basically I want to show the flag of the language I am currently writing in on TouchBar if possible. I would love for this action to be included in the BTT as one of the default widgets.

I don't need the widget to be actionable in any way, just show the flag for what language I am currently using.

Thank you.

1 Like

You can use this applescript in a widget to get your current language. You'll need to change/add the flag/icons of the languages you want though.

-- Get current language
set activeKbdLayout to my getActiveKeyboardLayout()
on getActiveKeyboardLayout()
set plistPath to "~/Library/Preferences/"
do shell script "defaults read " & plistPath & " dummy"
end try

tell application "System Events"
repeat with pli in property list items of ¬
property list item "AppleSelectedInputSources" of ¬
property list file plistPath
return value of property list item "KeyboardLayout Name" of pli
end try
end repeat
end tell
end getActiveKeyboardLayout

-- Make it return flag instead of words.

if activeKbdLayout is "Khmer" then

return ":cambodia:"

else if activeKbdLayout is "U.S." then

return ":us:"

else if activeKbdLayout is "Greek" then

return ":greece:"

else if activeKbdLayout is "French" then

return ":fr:"

else if activeKbdLayout is "Thai" then

return ":thailand:"

end if

Thank you. I made it work.

However to make it really work I need to run this script every second as I want to get the same behavior as what menu bar's keyboard input action has.

Is there any way that is more performant that constantly querying to see what language I currently have. As that seems expensive. :disappointed:

It likely won't make any noticable difference. But compare the energy impact in Activity Monitor (just make sure to close the BTT preference window while doing so or it will seem really high).

Also, I know you said it doesn't need to be actionable, but it is possible to make it so that pressing the button rotates between languages, or you can make a group with buttons for each language you use and set them to switch to that language when pressed. Like this:

Let me know if you want either of those options and I'll give you the script.

Is this still up to date for you? I made a shell script widget/group trigger for exactly this, can share it if you want.
(Besides being a shell script, I put the widget in my "settings group" with the setting "only run when visible").

1 Like

Please share it. I'm still looking for a good solution.

wait for it

Hi there @Doa.
The script doesn't seem to work with Chinese or Japanese. I think this may be because these languages have different input methods. The widget simply disappears when I switch the keyboard language to those languages. Any idea why?

Haven't used that button in ages, but just tried it, and it's not working at all. No idea why. Sorry

Is there any easy to use widget that will do this? I can't figure it out...