준호씨의 블로그

OSX - hammerspoon을 이용해서 한영전환 상태를 잘 보이게 만들기 본문

IT이야기

OSX - hammerspoon을 이용해서 한영전환 상태를 잘 보이게 만들기

준호씨 2023. 6. 2. 01:15
반응형

맥에서는 한/영 전환 상태를 확인하기가 쉽지 않습니다. 우측 상단 상태바에서 현재 언어 상태를 확인할 수 있기는 하지만 눈에 잘 들어오지 않습니다.

한/영 전환 상태를 확인하도록 하는 방법 중에 hammerspoon을 이용한 방법들이 보여서 적용해 보았습니다. 두 가지 방법이 보였는데 두 가지 모두 마음에 들어서 모두 적용하였습니다.

 

하나는 한/영 전환 시 화면 중앙에 국기 이미지와 한글/영문 텍스트를 표시해 주는 방식입니다.

현재 상태가 잠깐 나타났다가 다시 사라집니다.

 

두 번째는 화면 상단과 하단에 영문모드 일 때는 아무런 표시가 없다가 한글모드로 바뀌면 반투명 초록색 박스가 나타납니다.

아래쪽에도 나타납니다.

저는 두 가지 방법을 모두 적용하니 지금 변경되는 언어 설정도 바로 확인할 수 있고, 시간이 지나서 기억이 안 날 때는 색깔바를 보고 판단할 수 있어 좋았습니다.

 

hammerspoon 설치와 실행

hammerspoon이 없다면 hammerspoon을 설치합니다. 이미 설치되어 있다면 건너뜁니다.

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

 

inputsource_aurora.lua 파일 생성

"~/.hammerspoon/modules/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

 

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

require('modules.inputsource_aurora')

 

화면 우측 상단에 보이는 hammerspoon 아이콘을 누르고 Reload Config를 눌러서 설정을 불러오면 설정이 적용됩니다.

 

참고

https://jeonghwan-kim.github.io/think/2021/04/29/my-first-capacitive-keyboard.html

 

나의 첫 무접점 키보드

항상 컴퓨터로 일하는 사람들은 누구나 한 번 키보드에 욕심을 부려 보았을 것이다. 노트북에 내장된 것으로는 아쉬워서 외장 키보드를 연결해 사용하는데 그 가격만이 천차만별이다. 처음 해

jeonghwan-kim.github.io

https://johngrib.github.io/wiki/hammerspoon-inputsource-aurora/

 

해머스푼으로 한/영 전환 오로라를 만들자

지금 선택된 입력기가 한글인지 영어인지 쉽게 알아보자

johngrib.github.io

 

반응형
Comments