hammerspoon을 이용한 한영전환 가독성

riassuc·2021년 5월 26일
0

개발 관련해서 인터넷 검색을 하다가 어떤 개발자의 블로그를 보게 되었는데 hammerspoon을 알게 됐다.
개발 공부를 하면서 처음으로 맥을 사용하면서 평소에 윈도우 컴퓨터를 사용할 때 처럼 shift+space로 한/영전환을 사용하고 있었는데 가끔씩 빠르게 잘 안되고 밀리는 느낌이 있을 때가 있었는데 hammerspoon을 사용해서 더 한/영전환을 명시적으로 잘 보이게 할 수 있다.

hammerspoon은 lua라는 언어를 사용하지만 역시 인터넷에는 많은 정보가 있기 때문에 lua라는 언어를 처음 들어본 나도 쉽게 코드를 가져다가 사용 할 수 있었다.

작성일 기준 최신버전의 homebrew로 cask가 설치되어 있다면

brew install --cask hammerspoon

이 커맨드로 쉽게 설치할 수 있다.

설치 후 맥의 시스템 환경설정 - 보안 및 개인 정보 보호 - 손쉬운 사용에 hammerspoon을 추가해야 한다.

런치패드에서 hammerspoon을 실행 하면 상단바에 생기는데 클릭 후 Console...을 켜서

hs.keycodes.currentSourceID()

커맨드로 입력 소스를 확인 할 수 있는데
com.apple.keylayout.ABC 라는 결과가 나오면 문제없다.

그 후 ~/.hammerspoon 경로에
init.lua

require('modules.inputsource_aurora')

라고 작성 후

~/.hammerspoon/modules 경로에
inputsource_aurora.lua

-- style1

-- local boxes = {}
-- local inputEnglish = "com.apple.keylayout.ABC"
-- local box_height = 23
-- local box_alpha = 0.35
-- local GREEN = hs.drawing.color.osx_green

-- -- 입력소스 변경 이벤트에 이벤트 리스너를 달아준다
-- hs.keycodes.inputSourceChanged(function()
--     disable_show()
--     if hs.keycodes.currentSourceID() ~= inputEnglish 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



-- style2

hs.keycodes.inputSourceChanged(function(v)
    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
  
    hs.alert.closeAll()
    hs.alert.show(language)
  end)

주석처리해 놓은 style1, 아니면 style2 중에 원하는 것을 사용하면 된다.

이렇게 하면 한/영전환을 확실하게 알 수 있다.


profile
riassuc

0개의 댓글