Skip to content

Instantly share code, notes, and snippets.

@swcho
Created July 28, 2022 00:07
Show Gist options
  • Save swcho/95e7cb1a2b364f162cdc48e534113fdc to your computer and use it in GitHub Desktop.
Save swcho/95e7cb1a2b364f162cdc48e534113fdc to your computer and use it in GitHub Desktop.
나의 hammerspoon 설정
local inputEnglish = "com.apple.keylayout.ABC"
function hello()
local inputSource = hs.keycodes.currentSourceID()
if not (inputSource == inputEnglish) then
hs.eventtap.keyStroke({}, 'right')
hs.keycodes.currentSourceID(inputEnglish)
--hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
hs.eventtap.keyStroke({}, 'escape')
end
hs.eventtap.keyStroke({}, 'escape')
-- hs.eventtap.keyStroke({}, 'ESCAPE')
end
hs.hotkey.bind({'control'}, 33, hello)
-- --------------------------------------------------------------
local FRemap = require('foundation_remapping')
local remapper = FRemap.new()
remapper:remap('capslock', 'f18')
remapper:register()
local caps_mode = hs.hotkey.modal.new()
local inputEnglish = "com.apple.keylayout.ABC"
local on_caps_mode = function()
caps_mode:enter()
end
local off_caps_mode = function()
caps_mode:exit()
local input_source = hs.keycodes.currentSourceID()
if not (input_source == inputEnglish) then
hs.eventtap.keyStroke({}, 'right')
hs.eventtap.keyStroke({}, 'left')
hs.keycodes.currentSourceID(inputEnglish)
hs.eventtap.keyStroke({}, 'escape')
end
hs.eventtap.keyStroke({}, 'escape')
end
hs.hotkey.bind({}, 'f18', on_caps_mode, off_caps_mode)
-- function handleEscape()
-- local inputSource = hs.keycodes.currentSourceID()
-- if not (inputSource == inputEnglish) then
-- hs.eventtap.keyStroke({}, 'right')
-- hs.keycodes.currentSourceID(inputEnglish)
-- end
-- -- hs.eventtap.keyStroke({}, 'escape')
-- hs.eventtap.event.newKeyEvent('escape', true):post()
-- hs.eventtap.event.newKeyEvent('escape', false):post()
-- end
--
-- hs.hotkey.bind({}, 'escape', handleEscape)
hs.window.animationDuration = 0
units = {
right30 = { x = 0.70, y = 0.00, w = 0.30, h = 1.00 },
right50 = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 },
right70 = { x = 0.30, y = 0.00, w = 0.70, h = 1.00 },
left70 = { x = 0.00, y = 0.00, w = 0.70, h = 1.00 },
left50 = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 },
left30 = { x = 0.00, y = 0.00, w = 0.30, h = 1.00 },
top50 = { x = 0.00, y = 0.00, w = 1.00, h = 0.50 },
bot50 = { x = 0.00, y = 0.50, w = 1.00, h = 0.50 },
upright30 = { x = 0.70, y = 0.00, w = 0.30, h = 0.50 },
botright30 = { x = 0.70, y = 0.50, w = 0.30, h = 0.50 },
upleft70 = { x = 0.00, y = 0.00, w = 0.70, h = 0.50 },
botleft70 = { x = 0.00, y = 0.50, w = 0.70, h = 0.50 },
maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}
mash = { 'cmd', 'alt', 'ctrl' }
hs.hotkey.bind(mash, 'Right', function() hs.window.focusedWindow():move(units.right50, nil, true) end)
hs.hotkey.bind(mash, 'Left', function() hs.window.focusedWindow():move(units.left50, nil, true) end)
hs.hotkey.bind(mash, 'Up', function() hs.window.focusedWindow():move(units.top50, nil, true) end)
hs.hotkey.bind(mash, 'Down', function() hs.window.focusedWindow():move(units.bot50, nil, true) end)
hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end)
mash = { 'shift', 'ctrl', 'cmd' }
hs.hotkey.bind(mash, 'l', function() hs.window.focusedWindow():move(units.right30, nil, true) end)
hs.hotkey.bind(mash, 'h', function() hs.window.focusedWindow():move(units.left70, nil, true) end)
hs.hotkey.bind(mash, 'k', function() hs.window.focusedWindow():move(units.top50, nil, true) end)
hs.hotkey.bind(mash, 'j', function() hs.window.focusedWindow():move(units.bot50, nil, true) end)
hs.hotkey.bind(mash, ']', function() hs.window.focusedWindow():move(units.upright30, nil, true) end)
hs.hotkey.bind(mash, '[', function() hs.window.focusedWindow():move(units.upleft70, nil, true) end)
hs.hotkey.bind(mash, ';', function() hs.window.focusedWindow():move(units.botleft70, nil, true) end)
hs.hotkey.bind(mash, "'", function() hs.window.focusedWindow():move(units.botright30, nil, true) end)
hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function()
hs.reload()
end)
hs.alert.show("Config reloaded")
-- Ref: https://stackoverflow.com/a/58662204
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, 'n', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment