2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mac Hammerspoon / マルチモニタ環境でカーソルを対象モニタの画面中央に移動するホットキー

Last updated at Posted at 2020-04-11

序章

CatchMouseを使ってたんですがcmd+tabでアプリが候補に出てきてうざいなと思っていたので代替が無いかと探してました。
見つからないので Hammerspoon で対応できそうだなと思ったのでやりました

結果

普通に動いた。
Hammerspoon は MiroWindowsManager など他の機能も使っていたのでアプリをまとめられたのが良かった。

サンプル

${HOME}/.hammerspoon/Spoons/CatchMouse.spoon/init.lua
local obj={}
obj.__index = obj

-- Metadata
obj.name = "catchMouse"

function obj:bindHotkeys(mapping)

  for key,value in pairs(mapping) do
    local displayNo = value[1]
    local modifiers = value[2]
    local key = value[3];

    hs.hotkey.bind(modifiers, key, function ()
      moveDisplayCenter(hs.screen.allScreens()[displayNo])
    end)

  end

end

function moveDisplayCenter(screen)

  local screenFullFrame = screen:fullFrame()
  local screenCenterPoint = {}
  screenCenterPoint.x = screenFullFrame.x + screenFullFrame.w/2
  screenCenterPoint.y = screenFullFrame.y + screenFullFrame.h/2
  print(screenCenterPoint.x, screenCenterPoint.y)
  hs.mouse.setAbsolutePosition(screenCenterPoint)

end

function obj:init()
  print("Initializing CatchMouse")
end

return obj

${HOME}/.hammerspoon/init.lua
hs.loadSpoon("CatchMouse")

-- ホットキーのマッピング。
spoon.CatchMouse:bindHotkeys({
  -- monitor-index, modifier-keys, key
  {1, {"ctrl", "shift"}, "1"},
  {2, {"ctrl", "shift"}, "2"}
})

issue

ほんとうはgithubにあげてspoonsとして登録してもらえたら良いかな。とも思ってたけど案内見つからなかったので諦めた。

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?