LoginSignup
17
9

More than 3 years have passed since last update.

ShiftItをHammerspoonによって代替する

Last updated at Posted at 2020-09-22

ShiftItはmacOSでのウィンドウ配置によく利用されていたアプリだが、現状メンテナンスされていない。ShiftItのメンテナは、代替としてHammerspoonをお勧めしている。

ここではShiftitの

  • 右側へ横50%の幅で寄せる
  • 左側へ横50%の幅で寄せる
  • 上側へ縦50%の幅で寄せる
  • 下側へ縦50%の幅で寄せる
  • 縦横100%のサイズにする

という動作を、全く同じキーバインドで、Hammerspoonで代替してみる。

環境

  • MacBook Pro (16-inch 2019)
  • macOS Catalina 10.15.6

手順

  1. 公式サイトからHammerspoonをダウンロードし、/Applicationsフォルダへドラッグアンドドロップ
  2. Hammerspoonを起動し、メニューバーアイコン -> Preferences...
  3. 「Launch Hammerspoon at login」をチェックする
  4. 「Enable Accesibility」を押して、Macの設定からHammerspoonにアクセス権を与える
  5. これで準備が完了した。キーバインドを設定していく。

好きなターミナルを開き、以下のコードを貼り付ける。

cat <<EOH > ~/.hammerspoon/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 },
  maximum       = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}

mash = { 'option', 'ctrl', 'cmd' }
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)
EOH

終わったら、必ずメニューバーアイコンのHammerspoonから、「Reload Config」すること。

結果

これでShiftitの、

  • 右側へ横50%の幅で寄せる
  • 左側へ横50%の幅で寄せる
  • 上側へ縦50%の幅で寄せる
  • 下側へ縦50%の幅で寄せる
  • 縦横100%のサイズにする

が再現できた。

私はこのくらいしか使わないので他の機能は再現していないが、上記のスクリプトはLuaで書かれておりカスタマイズが可能である。Hammerspoonのドキュメント(特にキーコード)を読みながら、好きな機能を実装することもできると思われる。

参考

17
9
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
17
9