29 lines
1.1 KiB
Bash
Executable file
29 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
# from: https://apple.stackexchange.com/questions/251666/how-to-get-current-input-language-of-the-input-source
|
|
|
|
#!/usr/local/bin/bash
|
|
# Checks current keyboard input source (aka language)
|
|
|
|
#These are the strings that MacOS uses to identify the current input source
|
|
ENGLISH="Australian"
|
|
HIRIGANA="com.apple.inputmethod.Japanese"
|
|
KATANA="com.apple.inputmethod.Japanese.Katakana"
|
|
|
|
WESTERN_LANGUAGE=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep 'KeyboardLayout Name' | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')
|
|
|
|
# If the current language is not western one, then check a different variable
|
|
EASTERN_LANGUAGE=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | grep -w 'Input Mode' | head -1 | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/')
|
|
|
|
if [ "$WESTERN_LANGUAGE" = "$ENGLISH" ]; then
|
|
LABEL="English"
|
|
ICON="🇬🇧"
|
|
elif [ "$EASTERN_LANGUAGE" = "$HIRIGANA" ]; then
|
|
LABEL="Japanese"
|
|
ICON="🇯🇵"
|
|
elif [ "$EASTERN_LANGUAGE" = "$KATANA" ]; then
|
|
LABEL="Katakana"
|
|
ICON="🈴"
|
|
fi
|
|
|
|
sketchybar --set "$NAME" label="$LABEL" icon=""
|