ThinkMan
2018-11-16 19:58:48 +08:00
补上 hammerspoon 的脚本:
----------------------------------------------------------
-- 输入法设置成中文
----------------------------------------------------------
local function Chinese()
hs.keycodes.currentSourceID("com.apple.inputmethod.SCIM.Shuangpin")
hs.keycodes.setLayout("Pinyin")
end
----------------------------------------------------------
-- 输入法设置成英文
----------------------------------------------------------
local function English()
hs.keycodes.currentSourceID("com.apple.keylayout.ABC")
hs.keycodes.setLayout("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
----------------------------------------------------------
-- 设置各个 APP 打开时的输入法
----------------------------------------------------------
set_app_input_method("微信", Chinese)
set_app_input_method("Sublime Text", English)
set_app_input_method("终端", English)
-- 查看当前 APP Name 和输入发名称
hs.hotkey.bind({'ctrl', i}, ".", function()
hs.alert.show("App path: "
..hs.window.focusedWindow():application():path()
.."\n"
.."App name: "
..hs.window.focusedWindow():application():name()
.."\n"
.."IM source id: "
..hs.keycodes.currentSourceID())
end)