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.
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" 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.
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)
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.
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.
- I added a new "Top Level Trigger" (middle panel)
- Start typing "script" in the search field that popped up in "Select Trigger"
- Choose "Apple Script / Javascript Widget"
- I put Button Title as (2 lines):
INPUT
KB
- 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" 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
- 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
- Under Actions Assigned panel (middle right), I added a "Send Saved Shortcut" of: Control + Option + Spacebar
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...
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:
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.
after adding the double back slashes in the first line it works now! thanks a lot!!
Add this to change input directly from tapping the flag:
And add this to refresh the flag after tapping it so you wont have to wait 5 seconds for it to change:
Get the UUID here (yours will be different from mine) and paste it into the chunk I drew in red: