Skip to content

Instantly share code, notes, and snippets.

@junho85
Created June 1, 2023 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junho85/9ba87ed8b8cfd418166d8e087c10820e to your computer and use it in GitHub Desktop.
Save junho85/9ba87ed8b8cfd418166d8e087c10820e to your computer and use it in GitHub Desktop.
inputsource_aurora.lua
local boxes = {}
local box_height = 23
local box_alpha = 0.35
local GREEN = hs.drawing.color.osx_green
-- 입력소스 변경 이벤트에 이벤트 리스너를 달아준다
hs.keycodes.inputSourceChanged(function()
local inputSource = {
english = "com.apple.keylayout.ABC",
korean = "com.apple.inputmethod.Korean.2SetKorean",
}
local current = hs.keycodes.currentSourceID()
local language = nil
if current == inputSource.korean then
language = '🇰🇷 한글'
elseif current == inputSource.english then
language = '🇺🇸 영문'
else
language = current
end
-- alert
hs.alert.closeAll()
hs.alert.show(language)
-- boxes
disable_show()
if hs.keycodes.currentSourceID() ~= inputSource.english then
enable_show()
end
end)
function enable_show()
reset_boxes()
hs.fnutils.each(hs.screen.allScreens(), function(scr)
local frame = scr:fullFrame()
-- 상단 박스
local box = newBox()
draw_rectangle(box, frame.x, frame.y, frame.w, box_height, GREEN)
table.insert(boxes, box)
-- 하단 박스
local box2 = newBox()
draw_rectangle(box2, frame.x, frame.y + frame.h - 10, frame.w, box_height, GREEN)
table.insert(boxes, box2)
end)
end
function disable_show()
hs.fnutils.each(boxes, function(box)
if box ~= nil then
box:delete()
end
end)
reset_boxes()
end
function newBox()
return hs.drawing.rectangle(hs.geometry.rect(0,0,0,0))
end
function reset_boxes()
boxes = {}
end
function draw_rectangle(target_draw, x, y, width, height, fill_color)
-- 그릴 영역 크기를 잡는다
target_draw:setSize(hs.geometry.rect(x, y, width, height))
-- 그릴 영역의 위치를 잡는다
target_draw:setTopLeft(hs.geometry.point(x, y))
target_draw:setFillColor(fill_color)
target_draw:setFill(true)
target_draw:setAlpha(box_alpha)
target_draw:setLevel(hs.drawing.windowLevels.overlay)
target_draw:setStroke(false)
target_draw:setBehavior(hs.drawing.windowBehaviors.canJoinAllSpaces)
target_draw:show()
end
@junho85
Copy link
Author

junho85 commented Jun 1, 2023

@junho85
Copy link
Author

junho85 commented Jun 1, 2023

hammerspoon이 없으면 hammerspoon을 설치하고 실행해 줍니다.

brew install --cask hammerspoon && open -a hammerspoon

~/.hammerspoon/modules/inputsource_aurora.lua 파일을 생성해서 gist에 올린 코드를 복사하여 붙여넣습니다.

~/.hammerspoon/modules/init.lua 파일을 생성해서 inputsource_aurora를 사용하도록 설정합니다.

require('modules.inputsource_aurora')

hammerspoon 아이콘을 누르고 reload config를 합니다.
image

@junho85
Copy link
Author

junho85 commented Jun 1, 2023

내용은 https://junho85.pe.kr/2167 에 정리하였습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment