Skip to content

Instantly share code, notes, and snippets.

@fujohnwang
Forked from hongqn/HammerSpoonSwitchIME.lua
Created March 9, 2025 08:14
Show Gist options
  • Save fujohnwang/fb43392f40f4bc510675b5cbc7fe9bf0 to your computer and use it in GitHub Desktop.
Save fujohnwang/fb43392f40f4bc510675b5cbc7fe9bf0 to your computer and use it in GitHub Desktop.
local obj = {}
obj.__index = obj
-- Metadata
obj.name = "HammerspoonSwitchIME"
obj.version = "0.1"
obj.author = "Qiangning Hong"
obj.license = "MIT"
local ENGLISH_ID = "com.apple.keylayout.US"
local CHINESE_ID = "im.rime.inputmethod.Squirrel.Hans"
local JAPANESE_ID = "com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese"
local function switch(id)
hs.keycodes.currentSourceID(id)
end
function obj:bindHotkeys()
hs.hotkey.bind({"cmd", "alt"}, "e", function() switch(ENGLISH_ID) end)
hs.hotkey.bind({"cmd", "alt"}, "c", function() switch(CHINESE_ID) end)
hs.hotkey.bind({"cmd", "alt"}, "j", function() switch(JAPANESE_ID) end)
end
return obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment