# Language Menu Bar

**URL:** <https://community.folivora.ai/t/language-menu-bar/20957>\
**Category:** Setup/Preset Sharing\
**Created:** [January 21, 2021, 10:30am UTC](https://community.folivora.ai/t/language-menu-bar/20957 "2021-01-21T10:30:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [January 21, 2021, 10:30am UTC](https://community.folivora.ai/t/language-menu-bar/20957/1 "2021-01-21T10:30:17Z")

</div>

I am looking at the function embedded inside GoldenChaos - the language bar. I want to add a flag which was not originally included in the script nor the input type. The language I would want to add is Cangjie - Cantonese.

I tried adding:

```
else if activeKbdLayout contains "Cangjie - Cantonese" then
set activeKbdLayout to "🇭🇰"

```

but seems doesn't work... it just returns empty... kindly please help.

 ![Screenshot 2021-01-21 at 6.29.02 PM](https://community.folivora.ai/uploads/default/original/3X/c/c/cc186ab3340466b7f2bc3973a09318f0ca1500cc.png)

---

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [February 1, 2021, 2:52pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/2 "2021-02-01T14:52:23Z")

</div>

any insight?...

---

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [February 22, 2021, 1:32pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/3 "2021-02-22T13:32:02Z")

</div>

bump...

---

<div class="post-metadata">

**Author:** ![ideasbegan](https://community.folivora.ai/user_avatar/community.folivora.ai/ideasbegan/32/17145_2.png) [@ideasbegan](https://community.folivora.ai/u/ideasbegan)\
**Post date:** [February 23, 2021, 7:18pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/5 "2021-02-23T19:18:54Z")

</div>

Try using this script instead:

> set keyboardInput to do shell script "defaults read ~/Library/Preferences/com.apple.HIToolbox.plist \  
> AppleCurrentKeyboardLayoutInputSourceID"
> 
> if keyboardInput contains "[com.apple.keylayout.US](http://com.apple.keylayout.US)" then  
> set keyboardInput to "🇺🇸"  
> else if keyboardInput contains "com.apple.keylayout.British" then  
> set keyboardInput to "🇬🇧"  
> else if keyboardInput contains "com.apple.keylayout.PinyinKeyboard" then  
> set keyboardInput to "🇨🇳"  
> else if keyboardInput contains "com.apple.keylayout.CangjieKeyboard" then  
> set keyboardInput to "🇭🇰"  
> else  
> set keyboardInput to "🌐"  
> end if

If you have more inputs, switch to that input and open terminal and run this line to get its name:

> defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID

Then you can add a new line in the script.

---

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [February 24, 2021, 4:45pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/6 "2021-02-24T16:45:42Z")

</div>

Hi thanks for your reply. Do I just replace the original script with your script? It doesn't seem to work if just use your script and run.

The original script, as extracted from GoldenChaos is:

```
set activeKbdLayout to my getActiveKeyboardLayout()
on getActiveKeyboardLayout()
set plistPath to "~/Library/Preferences/com.apple.HIToolbox.plist"
try
	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
		try
			return value of property list item "KeyboardLayout Name" of pli
		end try
	end repeat
end tell
end getActiveKeyboardLayout

if activeKbdLayout contains "Australian" then
	set activeKbdLayout to "🇦🇺"
else if activeKbdLayout contains "British" then
	set activeKbdLayout to "🇬🇧"
(Truncated code below)
```

---

<div class="post-metadata">

**Author:** ![ideasbegan](https://community.folivora.ai/user_avatar/community.folivora.ai/ideasbegan/32/17145_2.png) [@ideasbegan](https://community.folivora.ai/u/ideasbegan)\
**Post date:** [February 24, 2021, 4:51pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/7 "2021-02-24T16:51:53Z")

</div>

Yeah... Should be direct replacement but our setups could be different. I'm on big sur with m1 so I can't test intel.

You could try to make a new top level trigger and choose type as run applescript. Paste that in and it should run just fine. Let me know...I can help troubleshoot.

---

<div class="post-metadata">

**Author:** ![ideasbegan](https://community.folivora.ai/user_avatar/community.folivora.ai/ideasbegan/32/17145_2.png) [@ideasbegan](https://community.folivora.ai/u/ideasbegan)\
**Post date:** [February 24, 2021, 5:41pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/8 "2021-02-24T17:41:53Z")

</div>

So...this is what I did. Decided to add one to my setup. Added shortcut to toggle between inputs too so you can tap it to change language.

1. I added a new "Top Level Trigger" (middle panel)
2. Start typing "script" in the search field that popped up in "Select Trigger"
3. Choose "Apple Script / Javascript Widget"
4. I put Button Title as (2 lines):  
INPUT  
KB
5. Copied below code into the script box:

> set keyboardInput to do shell script "defaults read ~/Library/Preferences/com.apple.HIToolbox.plist \  
> AppleCurrentKeyboardLayoutInputSourceID"
> 
> if keyboardInput contains "[com.apple.keylayout.US](http://com.apple.keylayout.US)" then  
> set keyboardInput to "US-EN\n🇺🇸"  
> else if keyboardInput contains "com.apple.keylayout.British" then  
> set keyboardInput to "GB-EN\n🇬🇧"  
> else if keyboardInput contains "com.apple.keylayout.PinyinKeyboard" then  
> set keyboardInput to "CN-PY\n🇨🇳"  
> else if keyboardInput contains "com.apple.keylayout.CangjieKeyboard" then  
> set keyboardInput to "HK-CJ\n🇭🇰"  
> else  
> set keyboardInput to "OTHER\n🌐"  
> end if

1. Under [Common] Tab:

- Button background: Black
- Item Placement (where you want to put it)
- Font Size 7, Font Size Second Line 18, Align Center
- Corner Radius 3
- HUD Title: Input, Detail: Keyboard Toggle

1. Under Actions Assigned panel (middle right), I added a "Send Saved Shortcut" of: Control + Option + Spacebar

 ![Touch Bar Shot 2021-02-24 at 12.32.55 PM](https://community.folivora.ai/uploads/default/original/3X/3/c/3c0c065adc8666121853319eaa3ca25663603615.png) ![Touch Bar Shot 2021-02-24 at 12.33.02 PM](https://community.folivora.ai/uploads/default/original/3X/4/1/41d9f46f098bf5d96b0bc9cb5365b296d52d1a08.png)

---

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [February 28, 2021, 2:53am UTC](https://community.folivora.ai/t/language-menu-bar/20957/9 "2021-02-28T02:53:51Z")

</div>

Hi, thanks for your detail walkthrough... but seems the script is not working properly on my side... I am using M1 on big sur as well. When I tried to do the Run Script in the Script box, it does not return anything from the "Script Results" as well...

 ![Screenshot 2021-02-28 at 10.52.06 AM](https://community.folivora.ai/uploads/default/original/3X/f/d/fd46aeb7a42c05a7895a26158c94ead29d932b41.jpeg)

---

<div class="post-metadata">

**Author:** ![ideasbegan](https://community.folivora.ai/user_avatar/community.folivora.ai/ideasbegan/32/17145_2.png) [@ideasbegan](https://community.folivora.ai/u/ideasbegan)\
**Post date:** [February 28, 2021, 3:19am UTC](https://community.folivora.ai/t/language-menu-bar/20957/10 "2021-02-28T03:19:18Z")

</div>

Not sure what happened...looks like pasting it here got some characters removed. I tweaked it a little more to look better on mine but here's a screenshot of what I currently have:

 ![Screen Shot 2021-02-27 at 10.20.03 PM](https://community.folivora.ai/uploads/default/original/3X/2/3/23a3ad52ee61764a1eef5293be3726aa7c435522.jpeg)

 ![Screen Shot 2021-02-27 at 10.21.08 PM](https://community.folivora.ai/uploads/default/original/3X/9/1/91f5aec40459d24fd79986fa71d3d62cd09f50ea.jpeg)

 ![Touch Bar Shot 2021-02-27 at 10.18.57 PM](https://community.folivora.ai/uploads/default/original/3X/7/3/7326b58b7d9a6b99c6bca5322f665cfcccc82e36.png)

Looks like you were missing the double back slashes in the first line. If that doesn't work you can try exporting the preset to a new file and uploading it here. I'll edit and repost.

---

<div class="post-metadata">

**Author:** ![chluk2425](https://community.folivora.ai/user_avatar/community.folivora.ai/chluk2425/32/17483_2.png) [@chluk2425](https://community.folivora.ai/u/chluk2425)\
**Post date:** [February 28, 2021, 9:15am UTC](https://community.folivora.ai/t/language-menu-bar/20957/11 "2021-02-28T09:15:47Z")

</div>

> [@ideasbegan](#):
>
> defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID

after adding the double back slashes in the first line it works now! thanks a lot!!

---

<div class="post-metadata">

**Author:** ![ideasbegan](https://community.folivora.ai/user_avatar/community.folivora.ai/ideasbegan/32/17145_2.png) [@ideasbegan](https://community.folivora.ai/u/ideasbegan)\
**Post date:** [February 28, 2021, 2:05pm UTC](https://community.folivora.ai/t/language-menu-bar/20957/12 "2021-02-28T14:05:04Z")

</div>

Add this to change input directly from tapping the flag:

 ![Screen Shot 2021-02-28 at 8.55.20 AM](https://community.folivora.ai/uploads/default/original/3X/f/2/f298834a08c2d9d97d721bd1690ffd91f1caee7b.png)

And add this to refresh the flag after tapping it so you wont have to wait 5 seconds for it to change:

 ![Screen Shot 2021-02-28 at 8.55.31 AM](https://community.folivora.ai/uploads/default/original/3X/b/e/be25b73b3901c05e940699f2d1c7568af03a76b7.png)

Get the UUID here (yours will be different from mine) and paste it into the chunk I drew in red:

 ![Screen Shot 2021-02-28 at 8.56.24 AM](https://community.folivora.ai/uploads/default/original/3X/a/4/a40c89392e1c6fd0f10f61352e636a9afe6c3235.png)
