我用 hammperspoon 实现过你想要的效果:
hs.hotkey.bind({"cmd"}, "space", switchInputMethod) -- 切换输入法
--------------------------------------------------------------------------------------
-- 切换输入法 --
--------------------------------------------------------------------------------------
-- 切换输入法
function switchInputMethod()
local sourceId = hs.keycodes.currentSourceID();
hs.eventtap.keyStroke({"ctrl", "shift"}, "l") -- 触发系统的输入法快捷键
-- 先关闭前面的提示
hs.alert.closeAll()
if sourceId == "
com.apple.keylayout.US" then
-- 简体拼音
-- hs.alert.show("简体拼音", alertStyle)
hs.keycodes.currentSourceID("com.apple.inputmethod.SCIM.ITABC")
else
-- 英文输入法
-- hs.alert.show("English", alertStyle)
hs.keycodes.currentSourceID("
com.apple.keylayout.US")
end
end