title: Cocoa: Learn currently selected keyboard layout / input language
body: <p>How do I learn currently selected keyboard layout / input language?</p>
  
  <p>I was playing with NSInputManager but wasn’t able to achieve anything.</p>
  
  <pre><code>[NSInputManager currentInputManager]
  </code></pre>
  
  <p>returns (null) (as reported with %@) and thus</p>
  
  <pre><code>[[NSInputManager currentInputManager] localizedInputManagerName]
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas? Thanks.</p>
  
  <p><strong>Edit:</strong> I also found out that an AppleSelectedInputSourcesChangedNotification gets posted into</p>
  
  <pre><code>[NSDistributedNotificationCenter defaultCenter]
  </code></pre>
  
  <p>when user changes the layout, however no information about the newly selected layout is “attached” to this notification.</p>