I have a few languages on my computer and it would be helpful if there could be a language changer widget.
The Spelling checker you mean, the one you can find in System Settings → Keyboard → Text?
Well, I made a shell script that checks for it:
#!/bin/sh
MULTI=`defaults read -g NSSpellCheckerAutomaticallyIdentifiesLanguages`
if [ $MULTI -eq 1 ]; then echo 🌐
else
MULTI=`defaults read -g NSPreferredSpellServerLanguage`
if [ $MULTI = fr ]; then echo 🇫🇷
elif [ $MULTI = de ]; then echo 🇩🇪
elif [ $MULTI = it ]; then echo 🇮🇹
elif [ $MULTI = en ]; then echo 🇺🇸
elif [ $MULTI = ro_RO ]; then echo 🇷🇴
elif [ $MULTI = Romanian ]; then echo 🇷🇴
else echo ❔
fi
fi
to change the language to Automatic by language run this script:
#!/bin/sh
MULTI=`defaults write -g NSSpellCheckerAutomaticallyIdentifiesLanguages 1`
to change the language to English run this script:
#!/bin/sh
MULTI=`defaults write -g NSSpellCheckerAutomaticallyIdentifiesLanguages 0; defaults write -g NSPreferredSpellServerLanguage en`
to change the language to French run this script:
#!/bin/sh
MULTI=`defaults write -g NSSpellCheckerAutomaticallyIdentifiesLanguages 0; defaults write -g NSPreferredSpellServerLanguage fr`
Etc. Basically replace the last two letters to what you get if you run defaults read -g NSPreferredSpellServerLanguage
in the Terminal.
It kinda works, but is a bit buggy sometimes. Not sure wether this isn't due to macOS though.
How about for languages that have various input methods? Is there a two letter code for those?
Set the language you want to know in the system settings, then run this terminal command:
defaults read -g NSPreferredSpellServerLanguage
You'll get a result such as en for "Automatic by Language", de for German, my self added language Romanian returns ro_RO. It's this result you have to paste at the end of the commands (attention, it's capital sensitive).
Thanks
Changing the language doesn't seem to help though. It just returns "en" as that is my system default
сделал виджет для переключения языка
111139's solution worked out for me. The core of the bttpreset file is to create a trigger action to hit a keyboard shortcut to change the language. The optional Mac script displays an icon matches the current selected language.
---- Apple Script ----
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
return "Unknown"
end getActiveKeyboardLayout
if activeKbdLayout is "U.S." then
return "🇺🇸"
else if activeKbdLayout is "Russian" then
return "🇷🇺"
else if activeKbdLayout is "Unknown" then
return "🏁"
else
return "🏁"
end if