LoginSignup
2
2

More than 1 year has passed since last update.

Macbookで画面分割をHammerspoonで行う

Posted at

きっかけ

MacBookで開発などを行っている際に、縦置きの外部ディスプレイを導入して、縦画面での上下分割をしたくて色々調べたので、そのメモを記載します。

無料なもの

  1. ShiftIt
    ShiftItに関する記事が多く出てきた。しかし、最近はメンテナンスされていない。
    ※(開発者のMacBookが盗まれて、Linuxに心移りされたのが原因らしい)

有料App

  1. Magnet
    紹介されている記事では250円として記載されていたので、そのくらいなら出しても良いかなと思い調べてみると、980円に値上がりしていた。(画面分割のために、980円は高い、、。)

スクリーンショット 2022-02-05 17.03.48.png

Hammerspoon

Shiftlnのメンテナンスに関するやりとりで、Hammerspoonが勧められていたので、導入してみた。

設定方法

画面分割の方法は下記ページが分かりやすかったので、詳細はそちらを見てください。

インストール

brew install hammerspoon --cask

画面分割設定

ステップ1 Preferencesの設定
  • Accessibilityが有効になっていることを確認します。
  • - (無効の場合)Appleの設定でHammerspoonに「アクセシビリティ」権限を付与します。
ステップ2 init.luaの設定
  • Hammerspoonメニューバーアイコンをクリックし、[Open Config]をクリックします。init.luaファイルが開かれます。

今回は、下記の四つをのショートカットを設定します。

  • ctrl(^) + cmd(⌘) + left
    • ウィンドウを画面の左半分
  • ctrl(^) + cmd(⌘) + right
    • ウィンドウを画面の右半分
  • ctrl(^) + cmd(⌘) + up
    • ウィンドウを画面の上半分
  • ctrl(^) + cmd(⌘) + down
    • ウィンドウを画面の下半分
init.lua
hs.window.animationDuration = 0
units = {
  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 },
  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 }
}

mash = { 'ctrl', 'command' }
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)
ステップ3 設定のリロード
  • Hammerspoonメニューバーアイコンをもう一度クリックし、[Reload Config]をクリックします。

結論

Magnetなどの有料appを使用せず、Hammerspoonを導入すれば上下の画面分割などが楽に行えるようになりました。

2
2
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
2