LoginSignup
0
0

ワイドモニターにおけるHammer Spoonのすすめ

Last updated at Posted at 2024-04-05

HammerSpoonとは

Hammerspoonは、macOS用のオープンソースの自動化ツールです。AppleScriptやAutomatorのような他の自動化ツールと比較して、Hammerspoonはより強力で柔軟性があります。

主な特徴は以下の通りです:

  • Luaスクリプティング:Hammerspoonは、設定やカスタマイズにLuaスクリプト言語を使用します。Luaは簡潔で習得が容易な言語であり、強力な機能を提供します。
  • キーボードショートカット:グローバルなキーボードショートカットを定義して、アプリケーションの起動、ウィンドウの操作、テキストの入力など、さまざまな操作を自動化できます。
  • ウィンドウ管理:ウィンドウの移動、リサイズ、配置を自動化できます。例えば、特定のキーを押すことで、ウィンドウを画面の半分のサイズに変更したり、別のモニターに移動したりできます。
  • アプリケーションの制御:アプリケーションの起動、終了、切り替えを自動化できます。また、アプリケーション内の特定の機能を実行するスクリプトを作成することもできます。
  • システムイベントの監視:ネットワークの変更、USB機器の接続、画面の解像度の変更など、さまざまなシステムイベントを監視し、それらに応じてアクションを実行できます。
  • モジュールの拡張性:Hammerspoonは、多数のモジュールを提供しており、機能を拡張できます。例えば、Webリクエストを送信したり、OSの通知を表示したり、オーディオデバイスを制御したりできます。

Hammerspoonは、開発者、パワーユーザー、効率を重視するユーザーに人気があります。繰り返し行う作業を自動化したり、ワークフローを最適化したりするのに役立ちます。ただし、Luaスクリプトの知識が必要であり、設定には多少の学習曲線があります。

by claude

筆者が使用しているLuaスクリプト

頻繁に使うのが、alt + cmd + [9, 0, left, right, up, down]
これで画面分割を左1/3や半分などにできます。
好みでキーバインド変えられるので気に入る配置で、、

hs.loadSpoon("ShiftIt")
spoon.ShiftIt:bindHotkeys({
  left = {{ 'alt', 'cmd' }, 'left' },
  right = {{ 'alt', 'cmd' }, 'right' },
  up = {{ 'alt', 'cmd' }, 'up' },
  down = {{ 'alt', 'cmd' }, 'down' },
  upleft = {{ 'alt', 'cmd' }, '1' },
  upright = {{ 'alt', 'cmd' }, '2' },
  botleft = {{ 'alt', 'cmd' }, '3' },
  botright = {{ 'alt', 'cmd' }, '4' },
  maximum = {{ 'alt', 'cmd' }, 'm' },
  toggleFullScreen = {{ 'alt', 'cmd' }, 'f' },
  toggleZoom = {{ 'alt', 'cmd' }, 'z' },
  center = {{ 'alt', 'cmd' }, 'c' },
  nextScreen = {{ 'alt', 'cmd' }, 'n' },
  previousScreen = {{ 'alt', 'cmd' }, 'p' },
  resizeOut = {{ 'alt', 'cmd' }, '=' },
  resizeIn = {{ 'alt', 'cmd' }, '-' }
})

hs.window.animationDuration = 0
units = {
  right33         = { x = 0.67, y = 0.00, w = 0.33, h = 1.00 },
  left33          = { x = 0.00, y = 0.00, w = 0.33, h = 1.00 },
  center33        = { x = 0.33, y = 0.00, w = 0.34, 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 },
  righttop        = { x = 0.50, y = 0.00, w = 0.50, h = 0.50 },
  rightbot        = { x = 0.50, y = 0.50, w = 0.50, h = 0.50 },
  lefttop         = { x = 0.00, y = 0.00, w = 0.50, h = 0.50 },
  leftbot         = { x = 0.00, y = 0.50, w = 0.50, h = 0.50 },
  center          = { x = 0.33, y = 0.00, w = 0.33, h = 1.00 },
  right50         = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 },
  left50          = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 },
}

mash = { 'alt', 'command' }
hs.hotkey.bind(mash, 'right', function() hs.window.focusedWindow():move(units.right33, nil, true) end)
hs.hotkey.bind(mash, 'left', function() hs.window.focusedWindow():move(units.left33, nil, true) end)
hs.hotkey.bind(mash, 'up', function() hs.window.focusedWindow():move(units.center33, nil, true) end)
hs.hotkey.bind(mash, '0', function() hs.window.focusedWindow():move(units.right50, nil, true) end)
hs.hotkey.bind(mash, '9', function() hs.window.focusedWindow():move(units.left50, nil, true) end)
hs.hotkey.bind(mash, '1', function() hs.window.focusedWindow():move(units.righttop, nil, true) end)
hs.hotkey.bind(mash, '2', function() hs.window.focusedWindow():move(units.lefttop, nil, true) end)
hs.hotkey.bind(mash, '3', function() hs.window.focusedWindow():move(units.leftbot, nil, true) end)
hs.hotkey.bind(mash, '4', function() hs.window.focusedWindow():move(units.rightbot, nil, true) end)
0
0
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
0
0