sketchybar: init

This commit is contained in:
Nico 2025-10-04 13:45:49 +10:00
parent ded82a8f8b
commit ae71080920
Signed by: nico
SSH key fingerprint: SHA256:XuacYOrGqRxC3jVFjfLROn1CSvLz85Dec6N7O9Gwu/0
10 changed files with 182 additions and 96 deletions

View file

@ -0,0 +1,29 @@
#!/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="$ICON"