|
|
@ -1,49 +1,59 @@ |
|
|
|
local function Chinese() |
|
|
|
log = hs.logger.new('ime', 'debug') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function zh() |
|
|
|
hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Rime") |
|
|
|
hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Rime") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
local function English() |
|
|
|
local function en() |
|
|
|
hs.keycodes.currentSourceID("com.apple.keylayout.ABC") |
|
|
|
hs.keycodes.currentSourceID("com.apple.keylayout.ABC") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function ko() |
|
|
|
|
|
|
|
hs.keycodes.currentSourceID("com.apple.inputmethod.Korean.HNCRomaja") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
-- app to expected ime config |
|
|
|
-- app to expected ime config |
|
|
|
local app2Ime = { |
|
|
|
local app2Ime = { |
|
|
|
{'/System/Library/CoreServices/Finder.app', 'Chinese'}, |
|
|
|
{'/System/Library/CoreServices/Finder.app', 'zh'}, |
|
|
|
{'/Applications/Alfred 4.app', 'Chinese'}, |
|
|
|
{'/Applications/Alfred 4.app', 'zh'}, |
|
|
|
{'/Applications/Bitwarden.app', 'Chinese'}, |
|
|
|
{'/Applications/Bitwarden.app', 'zh'}, |
|
|
|
{'/Applications/Dash.app', 'Chinese'}, |
|
|
|
{'/Applications/Dash.app', 'zh'}, |
|
|
|
{'/Applications/iTerm.app', 'Chinese'}, |
|
|
|
{'/Applications/iTerm.app', 'zh'}, |
|
|
|
{'/Applications/Lark.app', 'Chinese'}, |
|
|
|
{'/Applications/Lark.app', 'zh'}, |
|
|
|
{'/Applications/Xcode.app', 'Chinese'}, |
|
|
|
{'/Applications/Xcode.app', 'zh'}, |
|
|
|
{'/Applications/GoldenDict.app', 'Chinese'}, |
|
|
|
{'/Applications/GoldenDict.app', 'zh'}, |
|
|
|
{'/Applications/Google Chrome.app', 'Chinese'}, |
|
|
|
{'/Applications/Google Chrome.app', 'zh'}, |
|
|
|
{'/Applications/DingTalk.app', 'Chinese'}, |
|
|
|
{'/Applications/DingTalk.app', 'zh'}, |
|
|
|
{'/Applications/Kindle.app', 'Chinese'}, |
|
|
|
{'/Applications/KakaoTalk.app', 'ko'}, |
|
|
|
{'/Applications/NeteaseMusic.app', 'Chinese'}, |
|
|
|
{'/Applications/Kindle.app', 'zh'}, |
|
|
|
{'/Applications/WeChat.app', 'Chinese'}, |
|
|
|
{'/Applications/kitty.app', 'zh'}, |
|
|
|
{'/Applications/Lark.app', 'Chinese'}, |
|
|
|
{'/Applications/NeteaseMusic.app', 'zh'}, |
|
|
|
{'/Applications/System Preferences.app', 'Chinese'}, |
|
|
|
{'/Applications/Lark.app', 'zh'}, |
|
|
|
{'/Applications/MindNode.app', 'Chinese'}, |
|
|
|
{'/Applications/System Preferences.app', 'zh'}, |
|
|
|
{'/Applications/Obsidian.app', 'Chinese'}, |
|
|
|
{'/Applications/MindNode.app', 'zh'}, |
|
|
|
{'/Applications/Preview.app', 'Chinese'}, |
|
|
|
{'/Applications/Obsidian.app', 'zh'}, |
|
|
|
{'/Applications/Sketch.app', 'Chinese'}, |
|
|
|
{'/Applications/Preview.app', 'zh'}, |
|
|
|
{'/Applications/wechatwebdevtools.app', 'Chinese'}, |
|
|
|
{'/Applications/Sketch.app', 'zh'}, |
|
|
|
{'/Applications/WeChat.app', 'Chinese'}, |
|
|
|
{'/Applications/wechatwebdevtools.app', 'zh'}, |
|
|
|
{'/Users/einverne/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/201.8538.31/IntelliJ IDEA.app', 'Chinese'}, |
|
|
|
{'/Applications/WeChat.app', 'zh'}, |
|
|
|
|
|
|
|
{'/Users/einverne/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/201.8538.31/IntelliJ IDEA.app', 'zh'}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updateFocusAppInputMethod() |
|
|
|
function updateFocusAppInputMethod() |
|
|
|
local focusAppPath = hs.window.frontmostWindow():application():path() |
|
|
|
local focusAppPath = hs.window.frontmostWindow():application():path() |
|
|
|
|
|
|
|
log.d(focusAppPath) |
|
|
|
-- hs.alert.show(focusAppPath) |
|
|
|
-- hs.alert.show(focusAppPath) |
|
|
|
for index, app in pairs(app2Ime) do |
|
|
|
for index, app in pairs(app2Ime) do |
|
|
|
local appPath = app[1] |
|
|
|
local appPath = app[1] |
|
|
|
local expectedIme = app[2] |
|
|
|
local expectedIme = app[2] |
|
|
|
|
|
|
|
|
|
|
|
if focusAppPath == appPath then |
|
|
|
if focusAppPath == appPath then |
|
|
|
if expectedIme == 'English' then |
|
|
|
if expectedIme == 'en' then |
|
|
|
English() |
|
|
|
en() |
|
|
|
|
|
|
|
elseif expectedIme == 'zh' then |
|
|
|
|
|
|
|
zh() |
|
|
|
else |
|
|
|
else |
|
|
|
Chinese() |
|
|
|
ko() |
|
|
|
end |
|
|
|
end |
|
|
|
break |
|
|
|
break |
|
|
|
end |
|
|
|
end |
|
|
@ -64,7 +74,10 @@ end) |
|
|
|
|
|
|
|
|
|
|
|
-- Handle cursor focus and application's screen manage. |
|
|
|
-- Handle cursor focus and application's screen manage. |
|
|
|
function applicationWatcher(appName, eventType, appObject) |
|
|
|
function applicationWatcher(appName, eventType, appObject) |
|
|
|
if (eventType == hs.application.watcher.activated) then |
|
|
|
log.i(eventType) |
|
|
|
|
|
|
|
log.i("tet") |
|
|
|
|
|
|
|
log.i(hs.application.watcher.activated) |
|
|
|
|
|
|
|
if eventType == hs.application.watcher.activated then |
|
|
|
updateFocusAppInputMethod() |
|
|
|
updateFocusAppInputMethod() |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|