在init的 lua脚本中,下面的代码是为了在进入Terminal、ShortCat和Spolight的时候,默认切换到英文输入法

  local function Chinese() hs.console.printStyledtext("chinese") hs.keycodes.currentSourceID("com.apple.inputmethod.SCIM.ITABC") end local function English() hs.console.printStyledtext(hs.keycodes.currentSourceID()) hs.keycodes.currentSourceID("com.apple.keylayout.ABC") end local function set_app_input_method(app_name, set_input_method_function, event) event = event or hs.window.filter.windowFocused hs.window.filter.new(app_name) :subscribe(event, function() set_input_method_function() end) end set_app_input_method('Hammerspoon', English, hs.window.filter.windowCreated) set_app_input_method('Spotlight', English, hs.window.filter.windowCreated) set_app_input_method('Shortcat', English, hs.window.filter.windowCreated) set_app_input_method('Terminal', English)