Posts vim mac hammerspoons
Post
Cancel

vim mac hammerspoons

hammerspaoon

int.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
-- 1). short key
local bindKey = {"shift","cmd"}
do  -- app manager
  local app_man = require('modules.appman')
  hs.hotkey.bind(bindKey, 'c', app_man:toggle('Google Chrome'))
  hs.hotkey.bind(bindKey, 'j', app_man:toggle('IntelliJ IDEA'))
  hs.hotkey.bind(bindKey, 'v', app_man:toggle('Visual Studio Code'))
  -- hs.hotkey.bind(bindKey, 'n', app_man:toggle('Notes'))
  hs.hotkey.bind(bindKey, 'f', app_man:toggle('Firefox'))
  hs.hotkey.bind(bindKey, 'e', app_man:toggle('Finder'))
  hs.hotkey.bind(bindKey, 'p', app_man:toggle('Preview'))
  hs.hotkey.bind(bindKey, 'a', app_man:toggle('Safari'))
  hs.hotkey.bind(bindKey, 'k', app_man:toggle('KakaoTalk'))
  hs.hotkey.bind(bindKey, 'space', app_man:toggle('iTerm'))
  hs.hotkey.bind({'control','shift'}, 'escape', app_man:toggle('Activity Monitor')) 
end
-- 2 esc, eng


local inputEnglish = "com.apple.keylayout.ABC"

local esc_bind

function back_to_eng()
	local inputSource = hs.keycodes.currentSourceID()
	if not (inputSource == inputEnglish) then
		hs.keycodes.currentSourceID(inputEnglish)
	end
	esc_bind:disable()
	hs.eventtap.keyStroke({}, 'escape')
	esc_bind:enable()
end 
esc_bind = hs.hotkey.new({}, 'escape', back_to_eng):enable()

hs.hotkey.bind({'ctrl'}, '[', function()
  hs.eventtap.keyStroke({}, 'escape')
end)


hs.hotkey.bind({'ctrl'},'escape', '[', function()
  hs.keycodes.currentSourceID(inputEnglish)
--hs.eventtap.keyStroke({}, 'escape')
end)

appman.lua

moudule 폴더에 넣으면 됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local obj = {}
local app_mode = hs.hotkey.modal.new()

function obj:toggle(name, secondName)
    if secondName == nil then
        -- FIXME: uuid 말고 대책을 마련하라
        secondName = '85ED2184-ABF5-4924-AE3F-B702622B858D'
    end
    return function()

        local activated = hs.application.frontmostApplication()
        local path = string.lower(activated:path())

        if string.match(path, string.lower(name) .. '%.app$') or string.match(path, string.lower(secondName) .. '%.app$') then
            return activated:hide()
        end

        if not hs.application.launchOrFocus(name) then
            hs.application.launchOrFocus(secondName)
        end

        local screen = hs.window.focusedWindow():frame()
        local pt = hs.geometry.rectMidPoint(screen)
        hs.mouse.absolutePosition(pt)
        app_mode.triggered = true
    end
end

local function focusScreen(screen)
  local windows = hs.fnutils.filter(
      hs.window.orderedWindows(),
      hs.fnutils.partial(isInScreen, screen))
  local windowToFocus = #windows > 0 and windows[1] or hs.window.desktop()
  windowToFocus:focus()

  -- Move mouse to center of screen
  local center = hs.geometry.rectMidPoint(screen:fullFrame())
  hs.mouse.absolutePosition(center)
end

function obj.focusPreviousScreen()
    focusScreen(hs.window.focusedWindow():screen():previous())
end

function obj.focusNextScreen()
    focusScreen(hs.window.focusedWindow():screen():next())
end

function obj:init(mod, key)

    return self
end

return obj

Links

This post is licensed under CC BY 4.0 by the author.