Skip to content

Instantly share code, notes, and snippets.

@hongqn
Last active March 9, 2025 08:14
Show Gist options
  • Save hongqn/7fae6ddefb929ed5f1ab59d9148a2250 to your computer and use it in GitHub Desktop.
Save hongqn/7fae6ddefb929ed5f1ab59d9148a2250 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