How to find active input language? (keyboard, foreign language)

How to find the active input language?
Sometimes referred to as, currently selected keyboard layout.

Purpose is use in "If" action.

.

KM already has an action to set the input language:

But I can not find an action to query and return a value for input language currently selected.
I searched for Apple Scripts, too.

The active input language is displayed in menu bar in two ways:

  1. in words next to input source icon
  2. √ mark on input source drop-down

.

So, can see it, but the question is, how to use it in a KM "if" action?

An earlier post here showed how to find default system language.
A different post showed all available input source languages, like this:

.

But the question is how to find the active, currently selected, input language?

I have already searched KM wiki, documentation, and past forum posts.
Also searched Apple Script variables, environment variables, and system variables, in general.
Obviously I'm missing something, but what?

There are various script incantations which yield strings like:

"com.apple.keylayout.British"
"com.apple.inputmethod.SCIM.ITABC"
"com.apple.keylayout.Hebrew-QWERTY"
"com.apple.keylayout.Greek"

etc.

For example:

(function () {
    'use strict';

    ObjC.import('Carbon');
    ObjC.bindFunction('CFMakeCollectable', ['id', ['void *']]);

    return $.CFMakeCollectable(
            $.TISGetInputSourceProperty(
                $.TISCopyCurrentKeyboardInputSource(),
                $.kTISPropertyInputSourceID
            )
        )
        .js

})();
4 Likes

Worked perfectly.
Will have many uses.

Thank you @ComplexPoint, very much.

If there is any way I can return the favor, please tell me.
(How about a steak dinner the next time you come to Bangkok?)

2 Likes