Thanks for your sharing! But it seemed to only work with system input sources. And I have no idea about what's wrong with them? Is a third-parry input source incompatible?
Looking forward to your reply and the following is the script that I have typed in:
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
end getActiveKeyboardLayout
if activeKbdLayout = "ABC" then
set layoutName to "ABC"
else
set layoutName to "Squirrel"
end if
get layoutName