import Carbon
import Foundation
func string(_ s:TISInputSource,_ k:CFString)->String { guard let p=TISGetInputSourceProperty(s,k) else{return ""};return Unmanaged<CFString>.fromOpaque(p).takeUnretainedValue() as String }
let all=TISCreateInputSourceList(nil,true).takeRetainedValue() as! [TISInputSource]
let args=CommandLine.arguments
if args.count == 1 {for s in all {let id=string(s,kTISPropertyInputSourceID);if id.contains("Kotoeri") || id.contains("keylayout.US") {print(id)}};let s=TISCopyCurrentKeyboardInputSource().takeRetainedValue();print("CURRENT="+string(s,kTISPropertyInputSourceID))}
else {for s in all where string(s,kTISPropertyInputSourceID)==args[2] {if args[1]=="select" {print(TISEnableInputSource(s));print(TISSelectInputSource(s))} else if args[1]=="disable" {print(TISDisableInputSource(s))}}}
