How do I learn currently selected keyboard layout / input language?
I was playing with NSInputManager but wasn’t able to achieve anything.
returns (null) (as reported with %@) and thus
[[NSInputManager currentInputManager] localizedInputManagerName]
It would be the best for me to just get back a two-letter abbreviation of the language used like EN or FR, but the keyboard layout name as displayed in menubar will also work.
Any ideas? Thanks.
Edit: I also found out that an AppleSelectedInputSourcesChangedNotification gets posted into
when user changes the layout, however no information about the newly selected layout is “attached” to this notification.
Keyboard layout to language combinations are typically one-to-many, so while you can get the localized name of the currently selected keyboard layout (or, more generally, the input source), the source can be used to type text in many languages. Why do you want to do this?
That said, you can get information about the current text input source using Text Input Source Services. For example: