Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add language detection because god dammit Swedish!
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env osascript | ||
# Example call. | ||
#set activeKbdLayout to my getActiveKeyboardLayout() # ->, e.g., "U.S." | ||
|
||
on getActiveKeyboardLayout() | ||
|
||
# Surprisingly, using POSIX-style paths (even with '~') works with | ||
# the `property list file` type. | ||
set plistPath to "~/Library/Preferences/com.apple.HIToolbox.plist" | ||
|
||
# !! First, ensure that the plist cache is flushed and that the | ||
# !! *.plist file contains the current value; simply executing | ||
# !! `default read` against the file - even with a dummy | ||
# !! key - does that. | ||
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 | ||
# Look for (first) entry with key "KeyboardLayout Name" and return | ||
# its value. | ||
# Note: Not all entries may have a 'KeyboardLayout Name' key, | ||
# so we must ignore errors. | ||
try | ||
return value of property list item "KeyboardLayout Name" of pli | ||
end try | ||
end repeat | ||
|
||
end tell | ||
end getActiveKeyboardLayout | ||
set currentLanguage to getActiveKeyboardLayout() | ||
do shell script "echo " & quoted form of currentLanguage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
CURRENT_LANGUAGE=`apple-language` | ||
SWEDEN="🇸🇪" | ||
ISRAEL="🇮🇱" | ||
US="🇺🇸" | ||
|
||
|
||
case ${CURRENT_LANGUAGE} in | ||
ABC) | ||
echo ${US} | ||
;; | ||
Swedish) | ||
echo ${SWEDEN} | ||
;; | ||
Hebrew) | ||
echo ${ISRAEL} | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters