Change OSX keyboard layout(“input source”) programmatically via terminal or AppleScript?

You can do it using the Text Input Services API: NSArray* sources = CFBridgingRelease(TISCreateInputSourceList((__bridge CFDictionaryRef)@{ (__bridge NSString*)kTISPropertyInputSourceID : @”com.apple.keylayout.French” }, FALSE)); TISInputSourceRef source = (__bridge TISInputSourceRef)sources[0]; OSStatus status = TISSelectInputSource(source); if (status != noErr) /* handle error */; The dictionary in the first line can use other properties for other criteria for picking an input … Read more