diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-29 21:04:12 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-29 21:04:12 +0900 |
| commit | 166301f7cfdf7f9cc9e5b9596a97b62980f66157 (patch) | |
| tree | 95213420b01e7e29a506909f69ac8f3965215957 | |
| parent | 4c2e322fcd11c88a65e743d77b7e5d5d8f18be5b (diff) | |
modified plugins/get_input_source.sh, modified sketchybar/sketchybarrc
| -rwxr-xr-x | mac/.config/sketchybar/plugins/get_input_source.sh | 38 | ||||
| -rwxr-xr-x | mac/.config/sketchybar/sketchybarrc | 2 |
2 files changed, 31 insertions, 9 deletions
diff --git a/mac/.config/sketchybar/plugins/get_input_source.sh b/mac/.config/sketchybar/plugins/get_input_source.sh index 89dab2b..ccddfc1 100755 --- a/mac/.config/sketchybar/plugins/get_input_source.sh +++ b/mac/.config/sketchybar/plugins/get_input_source.sh @@ -1,13 +1,37 @@ #!/bin/sh -# hangul and english item +PLIST="$HOME/Library/Preferences/com.apple.HIToolbox.plist" -# Read the plist data -plist_data=$(defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources) -current_input_source=$(echo "$plist_data" | plutil -convert xml1 -o - - | grep -A1 'KeyboardLayout Name' | tail -n1 | cut -d '>' -f2 | cut -d '<' -f1) +get_source_id() { + /usr/bin/defaults read "$PLIST" AppleCurrentKeyboardLayoutInputSourceID 2>/dev/null && return 0 + /usr/libexec/PlistBuddy -c 'Print :AppleSelectedInputSources' "$PLIST" 2>/dev/null | + awk ' + BEGIN { RS=""; FS="\n" } + { + # split by entries, pick InputSourceID preceded by InputSourceKind + n=split($0, lines, "\n") + kind=""; id="" + for (i=1;i<=n;i++) { + if (lines[i] ~ /InputSourceKind/) { + if (lines[i] ~ /Keyboard Layout/) kind="kbd"; else kind="ime" + } else if (lines[i] ~ /InputSourceID/) { + sub(/.*= /,"",lines[i]); sub(/;$/,"",lines[i]); id=lines[i] + } + } + if (id != "") { + if (kind=="kbd") { print id; exit } # prefer kbd + last=id + } + } + END { if (last!="") print last }' +} -if [ "$current_input_source" = "ABC" ]; then - sketchybar --set input_source icon="" +SOURCE_ID="$(get_source_id | tr -d '"')" + +if printf %s "$SOURCE_ID" | grep -q 'com\.apple\.keylayout\.2SetHangul'; then + ICON="" else - sketchybar --set input_source icon="" + ICON="" fi + +sketchybar --set input_source icon="$ICON" diff --git a/mac/.config/sketchybar/sketchybarrc b/mac/.config/sketchybar/sketchybarrc index 6fbfb4b..8f67334 100755 --- a/mac/.config/sketchybar/sketchybarrc +++ b/mac/.config/sketchybar/sketchybarrc @@ -168,8 +168,6 @@ sketchybar --add item clock right \ padding_right=4 \ click_script="$PLUGIN_DIR/clock_click.sh" -source "$ITEM_DIR/music.sh" - sketchybar --add item music center \ --set music icon= \ icon.padding_left=8 \ |
